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 标志可能包含一个系统错误代码. |
在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])