SHARE
TWEET

File Search Recursive

a guest Jul 22nd, 2014 242 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Usage =>
  2.  
  3. $Path = @AppDataDir&'\Mozilla\Firefox\Profiles'
  4. $Array = _RecFileListToArray($Path, "*", 0, 1, 0)
  5. _ArrayDisplay($Array)
  6.  
  7. ;------------------------------------------------
  8.  
  9. Func _RecFileListToArray($sPath, $sFilter = "*", $iFlag = 0, $iRecur = 0, $iFullPath = 0)
  10.     Local $asFileList[1], $sFullPath
  11.     If Not FileExists($sPath) Then Return SetError(1, 1, "")
  12.     If StringRight($sPath, 1) <> "\" Then $sPath = $sPath & "\"
  13.     If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringInStr($sFilter, "|")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
  14.     If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
  15.     If Not ($iRecur = 0 Or $iRecur = 1) Then Return SetError(4, 4, "")
  16.     If $iFullPath = 0 Then
  17.         $sFullPath = $sPath
  18.     ElseIf $iFullPath = 1 Then
  19.         $sFullPath = ""
  20.     Else
  21.         Return SetError(5, 5, "")
  22.     EndIf
  23.     _FLTA_Search($sPath, $sFilter, $iFlag, $iRecur, $sFullPath, $asFileList)
  24.     If $asFileList[0] = 0 Then Return SetError(6, 6, "")
  25.     Return $asFileList
  26. EndFunc  ;==>_FileListToArray
  27.  
  28. Func _FLTA_Search($sStartFolder, $sFilter, $iFlag, $iRecur, $sFullPath, ByRef $asFileList)
  29.    
  30.     Local $hSearch, $sFile
  31.  
  32.     If StringRight($sStartFolder, 1) <> "\" Then $sStartFolder = $sStartFolder & "\"
  33. ;
  34.     $hSearch = FileFindFirstFile($sStartFolder & $sFilter)
  35.     If $hSearch > 0 Then
  36.         While 1
  37.             $sFile = FileFindNextFile($hSearch)
  38.             If @error Then ExitLoop
  39.             Switch $iFlag
  40.                 Case 0
  41.                     If $iRecur And StringInStr(FileGetAttrib($sStartFolder & $sFile), "D") <> 0 Then ContinueLoop
  42.                 Case 1
  43.                     If StringInStr(FileGetAttrib($sStartFolder & $sFile), "D") <> 0 Then ContinueLoop
  44.                 Case 2
  45.                     If StringInStr(FileGetAttrib($sStartFolder & $sFile), "D") = 0 Then ContinueLoop
  46.             EndSwitch
  47.             If $iFlag = 1 And StringInStr(FileGetAttrib($sStartFolder & $sFile), "D") <> 0 Then ContinueLoop
  48.             If $iFlag = 2 And StringInStr(FileGetAttrib($sStartFolder & $sFile), "D") = 0 Then ContinueLoop
  49.             _FLTA_Add($asFileList, $sFullPath, $sStartFolder, $sFile)
  50.         WEnd
  51.         FileClose($hSearch)
  52.         ReDim $asFileList[$asFileList[0] + 1]
  53.     EndIf
  54.    
  55.     If $iRecur = 1 Then
  56.         $hSearch = FileFindFirstFile($sStartFolder & "*.*")
  57.         If $hSearch > 0 Then
  58.             While 1
  59.                 $sFile = FileFindNextFile($hSearch)
  60.                 If @error Then ExitLoop
  61.                 If StringInStr(FileGetAttrib($sStartFolder & $sFile), "D") And ($sFile <> "." Or $sFile <> "..") Then
  62.                     If $iFlag <> 1 Then _FLTA_Add($asFileList, $sFullPath, $sStartFolder, $sFile)
  63.                     _FLTA_Search($sStartFolder & $sFile, $sFilter, $iFlag, $iRecur, $sFullPath, $asFileList)
  64.                 EndIf
  65.             WEnd
  66.             FileClose($hSearch)
  67.         EndIf
  68.     EndIf
  69.    
  70. EndFunc
  71.  
  72. Func _FLTA_Add(ByRef $asFileList, $sFullPath, $sStartFolder, $sFile)
  73.    
  74.     Local $sAddFolder
  75.    
  76.     $asFileList[0] += 1
  77.     If UBound($asFileList) <= $asFileList[0] Then ReDim $asFileList[UBound($asFileList) * 2]
  78.     If $sFullPath = "" Then
  79.         $sAddFolder = $sStartFolder
  80.     Else
  81.         $sAddFolder = StringReplace($sStartFolder, $sFullPath, "")
  82.     EndIf
  83.     $asFileList[$asFileList[0]] = $sAddFolder & $sFile
  84.    
  85. EndFunc
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top