BBC BASIC for Windows
Programming >> Database and Files >> Reading unicode filenames
http://bb4w.conforums.com/index.cgi?board=database&action=display&num=1409434236

Reading unicode filenames
Post by southwest on Aug 30th, 2014, 9:30pm

I'm trying to write a utility to convert utf-8 chars in filenames into their nearest ANSI equivalent, as well as shortening long filenames etc.

When I try to read filenames with the standard SYS FindFirstFile program, unusual chars come out as question marks. *Spool-ing *Dir produces the same result. A rummaging through Google suggests I should be using FindFirstFileW and similar calls, but nothing at all comes back from this.
Re: Reading unicode filenames
Post by rtr2 on Aug 30th, 2014, 9:55pm

on Aug 30th, 2014, 9:30pm, southwest wrote:
Google suggests I should be using FindFirstFileW and similar calls, but nothing at all comes back from this.

FindFirstFileW works for me:

Code:
      CP_UTF8 = &FDE9
      VDU 23,22,640;512;8,16,16,128+8 : REM Select UTF-8 mode
      *font Courier New
      PROClistdirectory_utf8
      END

      DEF PROClistdirectory_utf8
      LOCAL dir%, sh%, res%, utf8%
      DIM dir% LOCAL 317, utf8% LOCAL 260
      SYS "FindFirstFileW", "*"+CHR$0+CHR$0, dir% TO sh%
      IF sh% <> -1 THEN
        REPEAT
          SYS "WideCharToMultiByte", CP_UTF8, 0, dir%+44, -1, utf8%, 260, 0, 0
          PRINT $$utf8%
          SYS "FindNextFileW", sh%, dir% TO res%
        UNTIL res% = 0
        SYS "FindClose", sh%
      ENDIF
      ENDPROC 


Re: Reading unicode filenames
Post by southwest on Aug 30th, 2014, 10:09pm

Interesting.

I thought the SYS/API parameters were identical from the C examples I could find,
I suspected they were not, but further searching proved fruitless.

Thanks for pointing me in the right direction.