FileFindFirstFile
指定路径和文件匹配条件创建搜索句柄.
FileFindFirstFile ( "filename" )
参数
filename
|
被搜索对象的路径和文件名. (接受通配符 * 和 ?. 见备注)
|
返回值
成功:
|
返回搜索"句柄", 供 FileFindNextFile 函数调用.
|
失败:
|
返回 -1, 表示没有找到搜索对象. 如果文件夹为空, 则设置 @error 为 1.
|
备注
搜索不区分大小写.
通配符约定: 一般而言, 星号 * 表示 0 或多个字符, 问号 ? 表示 0 或一个字符.
若指定的搜索字符串中只有通配符(或 "*.*"), 请查看下面示例的返回值!
可以使用一个通配符来匹配部分文件名或扩展名,例如 a*.b?.
当扩展名使用 3 个字符搜索, 则任何以这 3 个字符开始的扩展名都将匹配,
例如 "*.log" 将匹配 "test.log_1". (在 Microsoft 文档资料中没有描述).
使用 FileFind... 函数完成搜索后, 务必调用 FileClose() 函数释放搜索句柄.
返回目录名称将根据是否有通配符而定.
该函数使用底层 Windows API, 此函数实际是在搜索长, 短文件名时寻找匹配值.
如果你得到意外的结果, 则验证它是否仅匹配了短文件名.
函数示例
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Assign a Local variable the search handle of all files in the current directory.
Local $hSearch = FileFindFirstFile("*.*")
; Check if the search was successful, if not display a message and return False.
If $hSearch = -1 Then
MsgBox($MB_SYSTEMMODAL, "", "Error: No files/directories matched the search pattern.")
Return False
EndIf
; Assign a Local variable the empty string which will contain the files names found.
Local $sFileName = "", $iResult = 0
While 1
$sFileName = FileFindNextFile($hSearch)
; If there is no more file matching the search.
If @error Then ExitLoop
; Display the file name.
$iResult = MsgBox(BitOR($MB_SYSTEMMODAL, $MB_OKCANCEL), "", "File: " & $sFileName)
If $iResult <> $IDOK Then ExitLoop ; If the user clicks on the cancel/close button.
WEnd
; Close the search handle.
FileClose($hSearch)
EndFunc ;==>Example
----------------------------------------
该函数可以通过命令 exect 调用
参见:
FileClose, FileFindNextFile
exect=$var_h=FileFindFirstFile('C:\Test\*.*')||_ViewValues('$var_h')||$var_sfile=FileFindNextFile($var_h)||_ViewValues('$var_sfile')||FileClose($var_h) ;;在测试目录中找到第一个文件/文件夹名称的示例
© Аверин Андрей для Total Commander Image Averin-And@yandex.ru
|