以下代码如何只显示有2级目录的目录路径,一级除外,有代码
本帖最后由 qddoit 于 2009-7-13 23:25 编辑#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=i.ico
#AutoIt3Wrapper_outfile=ListAllDir.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#Include <Array.au3>
$path = @ScriptDir
$DirList = myFileListToArray($path,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 目前此代码直接列出来当前所有目录路径
请教。如何只列出2级以上的目录,只有1级的目录不显示 懒得改代码 写了个判断
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=i.ico
#AutoIt3Wrapper_outfile=ListAllDir.exe
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#Include <Array.au3>
$path = "h:\"
$DirList = myFileListToArray($path, 0, 2)
_ArrayDisplay($DirList)
Func myFileListToArray($sPath, $rPath = 0, $iFlag = 0, $sPathExclude = 0)
Local $asFileList
$asFileList = myFileListToArrayTemp($asFileList, $sPath, $rPath, $iFlag, $sPathExclude)
Return $asFileList
EndFunc ;==>myFileListToArray
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 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
If Not StringInStr($sPath, "\", 0, 3) = 0 Then
ReDim $asFileList
$asFileList = $asFileList + 1
;为了方便查看所有多加了/\
$asFileList = $sPath & "\//////" & $sFile
EndIf
WEnd
FileClose($hSearch)
Return $asFileList
EndFunc ;==>myFileListToArrayTemp 呵呵~好用哦
:face (26):超级感谢~
棒啊!!! If Not StringInStr($sPath, "\", 0, 3) = 0 Then
能不能再解释下这句什么意思? 如果路径里只包含3个以下的“\” 则
页:
[1]