函数参考


_WinAPI_FindFirstFile

Searches a directory for a file or subdirectory with a name that matches a specific name.

#Include <WinAPIEx.au3>
_WinAPI_FindFirstFile ( $sPath, $pData )

参数

$sPath The directory or path, and the file name, which can include wildcard characters, for example, an asterisk
"*" or a question mark "?". If the string ends with a wildcard, period ".", or directory name, the user
must have access permissions to the root and all subdirectories on the path.
$pData A pointer to the $tagWIN32_FIND_DATA structure that receives information about a found file or directory.

返回值

Success The search handle.
失败: 返回 0 并设置 @error 标志为非 0 值, @extended 标志可能包含一个系统错误代码.

注意/说明

This function opens a search handle and returns information about the first file that the file system finds with
a name that matches the specified pattern. This may or may not be the first file or directory that appears in
a directory-listing application when given the same file name string pattern.

After the search handle is established, you can use it to search for other files that match the same pattern by
using the _WinAPI_FindNextFile() function.

If the function fails because no matching files can be found, the @extended flag will contain ERROR_FILE_NOT_FOUND (2)
system error code.

When the search handle is no longer needed, close it by using the _WinAPI_FindClose() function.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <Array.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global $tData, $pData, $hSearch, $File
Global $List[101][2] = [[0]]

$tData = DllStructCreate($tagWIN32_FIND_DATA)
$pData = DllStructGetPtr($tData)

$hSearch = _WinAPI_FindFirstFile(@ScriptDir & '\*', $pData)
While Not @error
    $File = DllStructGetData($tData, 'cFileName')
    Switch $File
        Case '.', '..'

        Case Else
            If Not BitAND(DllStructGetData($tData, 'dwFileAttributes'), $FILE_ATTRIBUTE_DIRECTORY) Then
                $List[0][0] += 1
                If $List[0][0] > UBound($List) - 1 Then
                    ReDim $List[UBound($List) + 100][2]
                EndIf
                $List[$List[0][0]][0] = $File
                $List[$List[0][0]][1] = _WinAPI_MakeQWord(DllStructGetData($tData, 'nFileSizeLow'), DllStructGetData($tData, 'nFileSizeHigh'))
            EndIf
    EndSwitch
    _WinAPI_FindNextFile($hSearch, $pData)
WEnd

Switch @extended
    Case 18 ; ERROR_NO_MORE_FILES

    Case Else
        MsgBox(16, @extended, _WinAPI_GetErrorMessage(@extended))
        Exit
EndSwitch

_WinAPI_FindClose($hSearch)

_ArrayDisplay($List, '_WinAPI_Find...', $List[0][0])