Sign in to follow this  
Followers 0
wolf9228

Autoit_Tree_FileFind /function

1 post in this topic

http://blogs.msdn.com/gstemp/archive/2004/08/11/213028.aspx

Optional: specifies whether to return files folders or both

$iFlag=0(Default) Return both files and folders

$iFlag=1 Return files only

$iFlag=2 Return Folders only

Autoit_Tree_FileFind.AU3

#include "Tree_FileFind.au3"
#Include <Array.au3>
;TTree_FileFind($szPath = "",$iFlag = 0 ,$extension = "")
;Optional: specifies whether to return files folders or both
;$iFlag=0(Default) Return both files and folders
;$iFlag=1 Return files only
;$iFlag=2 Return Folders only


$TIMINT = TimerInit()
$TREE_FileFind = Tree_FileFind( "C:\" , 2 , "")
$milliseconds = TimerDiff($TIMINT)
_ArrayDisplay($TREE_FileFind, "Tree_FileFind Return Folders only")
MsgBox(0,"Tree_FileFind","AUTOIT ==> milliseconds ==>  " & $milliseconds )



$TIMINT = TimerInit()
$TREE_FileFind = Tree_FileFind( @ProgramFilesDir , 1 , "exe")
$milliseconds = TimerDiff($TIMINT)
_ArrayDisplay($TREE_FileFind, "Tree_FileFind Return exe files only")
MsgBox(0,"Tree_FileFind","AUTOIT ==> milliseconds ==>  " & $milliseconds )

$TIMINT = TimerInit()
$TREE_FileFind = Tree_FileFind(@MyDocumentsDir , 0 , "")
$milliseconds = TimerDiff($TIMINT)
_ArrayDisplay($TREE_FileFind, "Tree_FileFind Return both files and folders")
MsgBox(0,"Tree_FileFind","AUTOIT ==> milliseconds ==>  " & $milliseconds )oÝ÷ Ù:ÞxX¥xX§u«·jëh×6;TTree_FileFind($szPath = "",$iFlag = 0 ,$extension = "")
;Optional: specifies whether to return files folders or both
;$iFlag=0(Default) Return both files and folders
;$iFlag=1 Return files only
;$iFlag=2 Return Folders only


Func Tree_FileFind($szPath = "",$iFlag = 0 ,$extension = "")
Local $TREE_Array[1] ,$FileFind_Array,$Files_Array,$Dirs_Array
$TREE_Array[0] = 0
$szPath = StringReplace($szPath , "\\" , "\" )
If StringRight($szPath,1) = "\" Then _
$szPath = StringTrimRight($szPath,1)
If Not FileExists($szPath) Then Return $TREE_Array
$FileFind_Array = FileFind($szPath ,$TREE_Array,$iFlag,$extension)
IF IsArray($FileFind_Array) Then
$Dirs_Array  = $FileFind_Array[1]
$TREE_Array  = $FileFind_Array[2]

For $I = 1 To $Dirs_Array[0]
$CHK_DRIVE = StringSplit($Dirs_Array[$I], "\")
If $CHK_DRIVE[0] < 3 Then
$FileFind_Array2 = FileFind($Dirs_Array[$I] ,$TREE_Array,$iFlag,$extension)
IF IsArray($FileFind_Array2) Then
$Dirs_Array2 = $FileFind_Array2[1]
$TREE_Array  = $FileFind_Array2[2]
For $I2 = 1 To $Dirs_Array2[0]
$TREE_Array = LoopTree_FileFind($Dirs_Array2[$I2],$iFlag,$extension ,$TREE_Array)
Next
EndIf
Else
$TREE_Array = LoopTree_FileFind($Dirs_Array[$I],$iFlag,$extension,$TREE_Array)
EndIf
Next
EndIf
Return $TREE_Array
EndFunc


Func FileFind($szPath , $TREE_Array , $iFlag , $extension)
Dim $FileFind_Array[4]
$FileFind_Array[0] = 2
Dim $Dirs_Array[1]
$Dirs_Array[0] = 0
FileChangeDir($szPath)
$sFilter = "*.*"
if $iFlag = 2 Then $sFilter = "*."
$search = FileFindFirstFile($sFilter)  
If $search = -1 Then Return -1
While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    Select
    Case StringInStr(FileGetAttrib($file), "D") = True 
    IF $iFlag <> 1 Then
    ReDim $TREE_Array[$TREE_Array[0] + 2]
    $TREE_Array[$TREE_Array[0] + 1] = $szPath & "\" & $file
    $TREE_Array[0] = $TREE_Array[0] + 1
    EndIf
    If StringInStr(FileGetAttrib($file), "S") = True Then _
    ContinueLoop
    ReDim $Dirs_Array[$Dirs_Array[0] + 2]
    $Dirs_Array[$Dirs_Array[0] + 1] = $szPath & "\" & $file
    $Dirs_Array[0] = $Dirs_Array[0] + 1
    
    
    
    
    Case StringInStr(FileGetAttrib($file), "D") = False
    Select
    If if $iFlag = 2 Then ContinueLoop
    Case StringLen(StringStripWS($extension, 8)) <> 0
    If Not (StringUpper(StringRight($file,StringLen($extension))) = StringUpper($extension)) _
    Then ContinueLoop
    ReDim $TREE_Array[$TREE_Array[0] + 2]
    $TREE_Array[$TREE_Array[0] + 1] = $szPath & "\" & $file
    $TREE_Array[0] = $TREE_Array[0] + 1
    Case StringLen(StringStripWS($extension, 8)) = 0
    ReDim $TREE_Array[$TREE_Array[0] + 2]
    $TREE_Array[$TREE_Array[0] + 1] = $szPath & "\" & $file
    $TREE_Array[0] = $TREE_Array[0] + 1
    EndSelect
    
    EndSelect
WEnd
FileClose($search)
FileChangeDir(@SCriptDir)
$FileFind_Array[1] = $Dirs_Array
$FileFind_Array[2] = $TREE_Array
Return $FileFind_Array
EndFunc



Func LoopTree_FileFind($szPath , $iFlag , $extension , $TREE_Array)
Local $FileFind_Array,$Files_Array,$Dirs_Array
$FileFind_Array = FileFind($szPath,$TREE_Array,$iFlag,$extension)
IF IsArray($FileFind_Array) Then
$Dirs_Array = $FileFind_Array[1]
$TREE_Array = $FileFind_Array[2]
For $I = 1 To $Dirs_Array[0]
$TREE_Array = LoopTree_FileFind($Dirs_Array[$I],$iFlag,$extension,$TREE_Array)
Next
EndIf
Return $TREE_Array
EndFunc

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0