User Tools

Site Tools


unicode_20filenames

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
unicode_20filenames [2018/03/31 13:19] – external edit 127.0.0.1unicode_20filenames [2024/01/05 00:21] (current) – external edit 127.0.0.1
Line 3: Line 3:
 //by Richard Russell, October 2016//\\ \\  Although //BBC BASIC for Windows// includes limited support for Unicode (UTF-8) strings, this support does not extend to directory and file names. Even if you explicitly select UTF-8 as the character set in a [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#usermode|VDU 23,22]] command, all the native statements and functions that require a path or a directory name still expect to receive them as ANSI strings. This is obviously a limitation if you want to access files or directories whose names include non-ASCII characters.\\ \\  To solve this problem I have listed below a number of replacement routines that can be used instead of the native equivalents. No replacement for **OPENOUT** is listed; it will normally be easier to create the file initially with an ASCII name and then to use **PROCrenameUTF8** to change the name to the required Unicode form.\\ \\  //by Richard Russell, October 2016//\\ \\  Although //BBC BASIC for Windows// includes limited support for Unicode (UTF-8) strings, this support does not extend to directory and file names. Even if you explicitly select UTF-8 as the character set in a [[http://www.bbcbasic.co.uk/bbcwin/manual/bbcwin8.html#usermode|VDU 23,22]] command, all the native statements and functions that require a path or a directory name still expect to receive them as ANSI strings. This is obviously a limitation if you want to access files or directories whose names include non-ASCII characters.\\ \\  To solve this problem I have listed below a number of replacement routines that can be used instead of the native equivalents. No replacement for **OPENOUT** is listed; it will normally be easier to create the file initially with an ASCII name and then to use **PROCrenameUTF8** to change the name to the required Unicode form.\\ \\ 
 ==== OPENIN: ==== ==== OPENIN: ====
 +<code bb4w>
         DEF FNopeninUTF8(utf8$)         DEF FNopeninUTF8(utf8$)
         LOCAL A%, R%, S%, W%         LOCAL A%, R%, S%, W%
Line 11: Line 12:
         SYS "WideCharToMultiByte", 0, 0, S%, -1, A%, 260, 0, 0         SYS "WideCharToMultiByte", 0, 0, S%, -1, A%, 260, 0, 0
         = OPENIN($$A%)         = OPENIN($$A%)
 +</code>
 \\  \\ 
 ==== OPENUP: ==== ==== OPENUP: ====
 +<code bb4w>
         DEF FNopenupUTF8(utf8$)         DEF FNopenupUTF8(utf8$)
         LOCAL A%, R%, S%, W%         LOCAL A%, R%, S%, W%
Line 21: Line 24:
         SYS "WideCharToMultiByte", 0, 0, S%, -1, A%, 260, 0, 0         SYS "WideCharToMultiByte", 0, 0, S%, -1, A%, 260, 0, 0
         = OPENUP($$A%)         = OPENUP($$A%)
 +</code>
 \\  \\ 
 ==== *DELETE/*ERASE: ==== ==== *DELETE/*ERASE: ====
 +<code bb4w>
         DEF PROCdeleteUTF8(utf8$)         DEF PROCdeleteUTF8(utf8$)
         LOCAL W%         LOCAL W%
Line 29: Line 34:
         SYS "DeleteFileW", W%         SYS "DeleteFileW", W%
         ENDPROC         ENDPROC
 +</code>
 \\  \\ 
 ==== *RENAME: ==== ==== *RENAME: ====
 +<code bb4w>
         DEF PROCrenameUTF8(old$, new$)         DEF PROCrenameUTF8(old$, new$)
         LOCAL O%, N%         LOCAL O%, N%
Line 38: Line 45:
         SYS "MoveFileW", O%, N%         SYS "MoveFileW", O%, N%
         ENDPROC         ENDPROC
 +</code>
 \\  \\ 
 ==== *MKDIR: ==== ==== *MKDIR: ====
 +<code bb4w>
         DEF PROCmkdirUTF8(utf8$)         DEF PROCmkdirUTF8(utf8$)
         LOCAL W%         LOCAL W%
Line 46: Line 55:
         SYS "CreateDirectoryW", W%, 0         SYS "CreateDirectoryW", W%, 0
         ENDPROC         ENDPROC
 +</code>
 \\  \\ 
 ==== *CHDIR: ==== ==== *CHDIR: ====
 +<code bb4w>
         DEF PROCchdirUTF8(utf8$)         DEF PROCchdirUTF8(utf8$)
         LOCAL W%         LOCAL W%
Line 54: Line 65:
         SYS "SetCurrentDirectoryW", W%         SYS "SetCurrentDirectoryW", W%
         ENDPROC         ENDPROC
 +</code>
 \\  \\ 
 ==== *RMDIR: ==== ==== *RMDIR: ====
 +<code bb4w>
         DEF PROCrmdirUTF8(utf8$)         DEF PROCrmdirUTF8(utf8$)
         LOCAL W%         LOCAL W%
Line 62: Line 75:
         SYS "RemoveDirectoryW", W%         SYS "RemoveDirectoryW", W%
         ENDPROC         ENDPROC
 +</code>
 \\  Note that none of these routines generates an error if, for example, the specified file does not exist. If you require this functionality you can easily check the value returned from the relevant API function to check whether it was successful or not (generally a non-zero returned value will signify success and zero will signify failure). \\  Note that none of these routines generates an error if, for example, the specified file does not exist. If you require this functionality you can easily check the value returned from the relevant API function to check whether it was successful or not (generally a non-zero returned value will signify success and zero will signify failure).
unicode_20filenames.1522502387.txt.gz · Last modified: 2024/01/05 00:16 (external edit)