QB64中文件名中的问号

时间:2017-09-01 03:40:13

标签: basic qbasic qb64

现在,我一直都知道以下字符是保留的,不能在文件名中使用:

/:*<> |“

然而,似乎有一个案例?字符(ascii 063)正在文件名中报告 包含Unicode。

我正在尝试使用FindFirstFileA获取文件名以准备复制和重命名它们,但我 不知道为什么函数返回?而不是Unicode。

我的问题是:如何处理文件名?在他们身上?

REM program displays filenames with question marks in them.
' declare library constants.
CONST MAX_PATH = 260 ' length of an ASCIIZ string
CONST INVALID_HANDLE_VALUE = -1 ' returned from a FindFirstFile
' declare library structures.
TYPE FILETIME
    dwLowDateTime AS _UNSIGNED LONG
    dwHighDateTime AS _UNSIGNED LONG
END TYPE
' windows structure for a FindFile
TYPE WIN32_FIND_DATAA
    dwFileAttributes AS _UNSIGNED LONG
    ftCreationTime AS FILETIME
    ftLastAccessTime AS FILETIME
    ftLastWriteTime AS FILETIME
    nFileSizeHigh AS _UNSIGNED LONG
    nFileSizeLow AS _UNSIGNED LONG
    dwReserved0 AS _UNSIGNED LONG
    dwReserved1 AS _UNSIGNED LONG
    cFileName AS STRING * MAX_PATH
    cAlternateFileName AS STRING * 14
END TYPE
' declare external libraries.
DECLARE DYNAMIC LIBRARY "kernel32"
    FUNCTION FindFirstFileA~%& (BYVAL lpFileName~%&, BYVAL lpFindFileData~%&)
    FUNCTION FindNextFileA& (BYVAL hFindFile~%&, BYVAL lpFindFileData~%&)
    FUNCTION FindClose& (BYVAL hFindFile~%&)
    FUNCTION GetLastError& ()
    FUNCTION SetCurrentDirectoryA% (f$)
END DECLARE
DIM Attribute AS INTEGER ' the attribute of a file
DIM ASCIIZ AS STRING * 260 ' a null terminated filename
DIM finddata AS WIN32_FIND_DATAA ' the windows filename stcucture
DIM Wfile.Handle AS _UNSIGNED _OFFSET ' windows file handle for FindFile
' force default path
x$ = _STARTDIR$
f$ = x$ + CHR$(0)
x = SetCurrentDirectoryA(f$)
' make filename
Var$ = "*.txt"
PRINT "Processing: "; Var$
ASCIIZ = Var$ + CHR$(0)
' start the search and store the returned windows file handle
Wfile.Handle = FindFirstFileA(_OFFSET(ASCIIZ), _OFFSET(finddata))
' check if the file handle is valid
IF Wfile.Handle <> INVALID_HANDLE_VALUE THEN
    ' search through the filenames
    DO
        ' check directory attribute
        Attribute = finddata.dwFileAttributes
        ' make sure the file found is a file and not a directory
        IF (Attribute AND &H10) = &H0 THEN
            ' get the matching filename from the windows structure
            Filename$ = finddata.cFileName
            Filename$ = LEFT$(Filename$, INSTR(Filename$, CHR$(0)) - 1)
            ' check wildcards (ascii 063)
            Var = INSTR(Filename$, "?") ' check for a Unicode character
            IF Var THEN
                PRINT Filename$
            END IF
        END IF
        ' continue loop if more files exist in search specification
    LOOP WHILE FindNextFileA(Wfile.Handle, _OFFSET(finddata))
    ' release window file handle to structure
    x = FindClose(Wfile.Handle)
END IF
END

0 个答案:

没有答案