找回密码
 加入
搜索
查看: 3293|回复: 6

如何用AU3列出目录内的所有文件夹名?

[复制链接]
发表于 2008-8-31 03:59:40 | 显示全部楼层 |阅读模式
如何用AU3列出目录内的所有文件夹名?

[ 本帖最后由 net_e 于 2008-9-4 03:28 编辑 ]
发表于 2008-9-1 14:29:08 | 显示全部楼层

代码如下

#Include <Array.au3>
$DirList = myFileListToArray("c:\",0,2)
_ArrayDisplay($DirList)



Func  myFileListToArray($sPath,  $rPath  =  0,  $iFlag  =  0,  $sPathExclude  =  0)
    Local  $asFileList[1]       
    $asFileList  =  myFileListToArrayTemp($asFileList,  $sPath,  $rPath,  $iFlag,  $sPathExclude)
    Return  $asFileList
EndFunc  

Func  myFileListToArrayTemp(ByRef  $asFileList,  $sPath,  $rPath  =  0,  $iFlag  =  0,  $sPathExclude  =  0)
    Local  $hSearch,  $sFile
    If  Not  FileExists($sPath)  Then  Return  SetError(1,  1,  "")
    If  Not  ($iFlag  =  0  Or  $iFlag  =  1  Or  $iFlag  =  2)  Then  Return  SetError(3,  3,  "")
    $hSearch  =  FileFindFirstFile($sPath  &  "\*")
    If  $hSearch  =  -1  Then  Return  SetError(4,  4,  "")
    While  1
        $sFile  =  FileFindNextFile($hSearch)
        If  @error  Then
            SetError(0)
            ExitLoop
        EndIf
        
    
        If  $sPathExclude  And  StringLen($sPathExclude)  >  0  Then  $sPathExclude  =  StringSplit($sPathExclude,  ",")
        $bExclude  =  False
        If  IsArray($sPathExclude)  Then
            For  $ii  =  1  To  $sPathExclude[0]  Step  1
                If  StringInStr($sPath  &  "\"  &  $sFile,  $sPathExclude[$ii])  Then
                    $bExclude  =  True
                    ExitLoop
                EndIf
            Next
        EndIf
        If  $bExclude  Then  ContinueLoop
        
        Select
            Case  StringInStr(FileGetAttrib($sPath  &  "\"  &  $sFile),  "D")  
                Select
                    Case  $iFlag  =  1   
                        myFileListToArrayTemp($asFileList,  $sPath  &  "\"  &  $sFile,  $rPath,  $iFlag,  $sPathExclude)
                        ContinueLoop    
                    Case  $iFlag  =  2  Or  $iFlag  =  0    
                        If  $rPath  Then   
                            If  Not  StringRegExp($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
                
            Case  Not  StringInStr(FileGetAttrib($sPath  &  "\"  &  $sFile),  "D")    
                If  $iFlag  =  2  Then  ContinueLoop   
                If  $rPath  And  Not  StringRegExp($sPath  &  "\"  &  $sFile,  $rPath,  0)  Then  ContinueLoop
        EndSelect
        
        ReDim  $asFileList[UBound($asFileList)  +  1]
        $asFileList[0]  =  $asFileList[0]  +  1
        $asFileList[UBound($asFileList)  -  1]  =  $sPath  &  "\"  &  $sFile
        
    WEnd
    FileClose($hSearch)
    Return  $asFileList
EndFunc    
 楼主| 发表于 2008-9-2 05:29:32 | 显示全部楼层
不是这个:)我只要得到目录名:)
发表于 2008-9-2 06:46:16 | 显示全部楼层
我在udf那个区里放过一个函数,看看也许有助,把参数改一下应该可以
发表于 2008-9-2 08:31:21 | 显示全部楼层
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)
 楼主| 发表于 2008-9-6 09:01:23 | 显示全部楼层
#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[0]
        msgbox(0,"",$FileList[$i])
Next
 楼主| 发表于 2008-9-6 09:01:36 | 显示全部楼层
#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[0]
        msgbox(0,"",$FileList[$i])
Next
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-11 22:17 , Processed in 0.072238 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表