【已解决】关于_FileListToArray 自定义函数 大家来看看这个两段代码
本帖最后由 linkuncool 于 2010-9-8 18:10 编辑这个令我很头痛
#Include <File.au3>
#Include <Array.au3>
For $i = 0 to 10 step 1
DirCreate ("d:\123\$"&$i&"$")
Next
$folderlist=_FileListToArray ("d:\123")
If $folderlist=0 Then
MsgBox (0,"","发生错误")
ElseIf @error = 1 Then
MsgBox (0,"","Path not found or invalid")
ElseIf @error = 2 Then
MsgBox (0,"","Invalid $sFilter")
ElseIf @error = 3 Then
MsgBox (0,"","Invalid $iFlag")
ElseIf @error = 4 Then
MsgBox (0,"","No File(s) Found")
Else
_ArrayDisplay($FolderList,"$FileList")
EndIf
上面的代码 _FileListToArray 不带参数运行OK
#Include <File.au3>
#Include <Array.au3>
For $i = 0 to 10 step 1
DirCreate ("d:\123\$"&$i&"$")
Next
$folderlist=_FileListToArray ("d:\123",2)
If $folderlist=0 Then
MsgBox (0,"","发生错误")
ElseIf @error = 1 Then
MsgBox (0,"","Path not found or invalid")
ElseIf @error = 2 Then
MsgBox (0,"","Invalid $sFilter")
ElseIf @error = 3 Then
MsgBox (0,"","Invalid $iFlag")
ElseIf @error = 4 Then
MsgBox (0,"","No File(s) Found")
Else
_ArrayDisplay($FolderList,"$FileList")
EndIf
我需要返回的是文件夹的列表
参数2 代表 返回文件夹名列表
执行失败
#Include <File.au3>
#Include <Array.au3>
For $i = 0 to 10 step 1
DirCreate ("d:\123\$"&$i&"$")
Next
$folderlist=_FileListToArray ("d:\123","",2)
If $folderlist=0 Then
MsgBox (0,"","发生错误")
ElseIf @error = 1 Then
MsgBox (0,"","Path not found or invalid")
ElseIf @error = 2 Then
MsgBox (0,"","Invalid $sFilter")
ElseIf @error = 3 Then
MsgBox (0,"","Invalid $iFlag")
ElseIf @error = 4 Then
MsgBox (0,"","No File(s) Found")
Else
_ArrayDisplay($FolderList,"$FileList")
EndIf
这样也不行
返回以前只是需要文件名的返回值
今天需要文件夹的昨天晚上就开始调试了
实在不知道为什么
帮助文件里写的清清楚楚啊 回复 1# linkuncool
这样可以#Include <File.au3>
#Include <Array.au3>
For $i = 0 to 10 step 1
DirCreate ("D:\AU3\$"&$i&"$")
Next
$folderlist=_FileListToArray ("D:\AU3","*.*",2)
If $folderlist=0 Then
MsgBox (0,"","发生错误")
ElseIf @error = 1 Then
MsgBox (0,"","Path not found or invalid")
ElseIf @error = 2 Then
MsgBox (0,"","Invalid $sFilter")
ElseIf @error = 3 Then
MsgBox (0,"","Invalid $iFlag")
ElseIf @error = 4 Then
MsgBox (0,"","No File(s) Found")
Else
_ArrayDisplay($FolderList,"$FileList")
EndIf 如果123 中用 文件存在 就不行了再说了 _FileListToArray 这个函数我们都指定 返回的是文件夹了 filter 根本就不需要啊 , 返回文件列表的话需要的话 需要声明下
之前已经解决 实现了 获取指定的 文件夹列表
我就是奇怪 为什么帮助文件里 写的清清楚楚 的
执行后出问题呢 用文件存在也可以阿
$folderlist=_FileListToArray ("d:\123","*",1)
你看File.au3
Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
Local $hSearch, $sFile, $sFileList, $sDelim = "|"
$sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\" ; ensure single trailing backslash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & $sFilter)
If @error Then Return SetError(4, 4, "")
While 1
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If ($iFlag + @extended = 2) Then ContinueLoop
$sFileList &= $sDelim & $sFile
WEnd
FileClose($hSearch)
If Not $sFileList Then Return SetError(4, 4, "")
Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc;==>_FileListToArray
看这个
_FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
如果这样写$folderlist=_FileListToArray ("d:\123",2)
把$sFilter 当成2了,要使用$iFlag参数必须写$sFilter参数
代码是从左边开始读,什么函数都一样,不能跳过前边的参数 回复 1# linkuncool
看帮助了吗?仔细看了吗?参数用对了吗?
请不要随意说XXX有BUG,XXX运行出错!
借用P大的话,先自行检查1000次。
#Include <File.au3>
#Include <Array.au3>
For $i = 0 to 10 step 1
DirCreate ("d:\123\$"&$i&"$")
Next
$folderlist=_FileListToArray ("d:\123","*",2);注意参数,别偷懒
If $folderlist=0 Then
MsgBox (0,"","发生错误")
ElseIf @error = 1 Then
MsgBox (0,"","Path not found or invalid")
ElseIf @error = 2 Then
MsgBox (0,"","Invalid $sFilter")
ElseIf @error = 3 Then
MsgBox (0,"","Invalid $iFlag")
ElseIf @error = 4 Then
MsgBox (0,"","No File(s) Found")
Else
_ArrayDisplay($FolderList,"$FileList")
EndIf 回复 2# lixiaolong
file.au3我看了下里面的filter=*是默认的
还一直在想文件夹又不分类型 filter 哪来干什么用
help 写 the filter to use, default is *.
我的错 学习。。。谢谢 真需要这个 改P大的話 !加倍學習1000次!
页:
[1]