如何用AU3列出目录内的所有文件夹名?
如何用AU3列出目录内的所有文件夹名?[ 本帖最后由 net_e 于 2008-9-4 03:28 编辑 ]
代码如下
#Include <Array.au3>$DirList = myFileListToArray("c:\",0,2)
_ArrayDisplay($DirList)
FuncmyFileListToArray($sPath,$rPath=0,$iFlag=0,$sPathExclude=0)
Local$asFileList
$asFileList=myFileListToArrayTemp($asFileList,$sPath,$rPath,$iFlag,$sPathExclude)
Return$asFileList
EndFunc
FuncmyFileListToArrayTemp(ByRef$asFileList,$sPath,$rPath=0,$iFlag=0,$sPathExclude=0)
Local$hSearch,$sFile
IfNotFileExists($sPath)ThenReturnSetError(1,1,"")
IfNot($iFlag=0Or$iFlag=1Or$iFlag=2)ThenReturnSetError(3,3,"")
$hSearch=FileFindFirstFile($sPath&"\*")
If$hSearch=-1ThenReturnSetError(4,4,"")
While1
$sFile=FileFindNextFile($hSearch)
If@errorThen
SetError(0)
ExitLoop
EndIf
If$sPathExcludeAndStringLen($sPathExclude)>0Then$sPathExclude=StringSplit($sPathExclude,",")
$bExclude=False
IfIsArray($sPathExclude)Then
For$ii=1To$sPathExcludeStep1
IfStringInStr($sPath&"\"&$sFile,$sPathExclude[$ii])Then
$bExclude=True
ExitLoop
EndIf
Next
EndIf
If$bExcludeThenContinueLoop
Select
CaseStringInStr(FileGetAttrib($sPath&"\"&$sFile),"D")
Select
Case$iFlag=1
myFileListToArrayTemp($asFileList,$sPath&"\"&$sFile,$rPath,$iFlag,$sPathExclude)
ContinueLoop
Case$iFlag=2Or$iFlag=0
If$rPathThen
IfNotStringRegExp($sPath&"\"&$sFile,$rPath,0)Then
myFileListToArrayTemp($asFileList,$sPath&"\"&$sFile,$rPath,$iFlag,$sPathExclude)
ContinueLoop
Else
myFileListToArrayTemp($asFileList,$sPath&"\"&$sFile,$rPath,$iFlag,$sPathExclude)
EndIf
Else
myFileListToArrayTemp($asFileList,$sPath&"\"&$sFile,$rPath,$iFlag,$sPathExclude)
EndIf
EndSelect
CaseNotStringInStr(FileGetAttrib($sPath&"\"&$sFile),"D")
If$iFlag=2ThenContinueLoop
If$rPathAndNotStringRegExp($sPath&"\"&$sFile,$rPath,0)ThenContinueLoop
EndSelect
ReDim$asFileList
$asFileList=$asFileList+1
$asFileList=$sPath&"\"&$sFile
WEnd
FileClose($hSearch)
Return$asFileList
EndFunc 不是这个:)我只要得到目录名:) 我在udf那个区里放过一个函数,看看也许有助,把参数改一下应该可以 Help 裡面標準範例有符合您的需求嗎?
; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("*.")
; Check if the search was successful
If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")
Exit
EndIf
While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
MsgBox(4096, "File:", $file)
WEnd
; Close the search handle
FileClose($search)
#Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray("dir","*.*",1)
If @Error=1 Then
MsgBox (0,"","No Files\Folders Found.")
Exit
EndIf
;_ArrayDisplay($FileList,"$FileList")
For$i=1 to $FileList
msgbox(0,"",$FileList[$i])
Next #Include <File.au3>
#Include <Array.au3>
$FileList=_FileListToArray("dir","*.*",2)
If @Error=1 Then
MsgBox (0,"","No Files\Folders Found.")
Exit
EndIf
;_ArrayDisplay($FileList,"$FileList")
For$i=1 to $FileList
msgbox(0,"",$FileList[$i])
Next
页:
[1]