Cocolas Posted May 18, 2017 Share Posted May 18, 2017 Hello, I've made a script to recursive search files with _FileListToArrayXT, I give it a folder and it recursive search in the first one, record the result in a text file and do the same to the next... But the problem is the process size, I've tried to flush the array that store files path but no result. Is there a way to flush the process or to get variable size? Thanks Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted May 18, 2017 Moderators Share Posted May 18, 2017 Probably, although it is a bit difficult to make any suggestions without seeing code. How about you help us help you "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Cocolas Posted May 18, 2017 Author Share Posted May 18, 2017 Of course ^_^' expandcollapse popup#include <File.au3> #include<Array.au3> #include <Date.au3> ;ouverture du fichier de paramètres $file = FileOpen(@scriptdir & "\Liste.txt", 0) $poids=0 $chemin="C:\" $trouve=False If $file <> -1 Then While 1 ;lecture du fichier $line = FileReadLine($file) If @error = -1 Then ExitLoop ;si il existe un = dans la ligne on la lit if StringInStr($line,"=")> 0 then $aArray = StringSplit($line,"=") ;si la ligne concerne le chemin on la récupère if StringLower($aArray[1])="chemin" Then $chemin = $aArray[2] Else if StringLower($aArray[1])="poids" Then $poids = $aArray[2] else ;si la ligne concerne les extensions on la lit if StringLower($aArray[1])="extensions" Then $trouve=True $extensions=$aArray[2] ;Recherche des fichiers $doss = FileFindFirstFile($chemin & "\*.*") ;écriture dans le fichier text Fichiers.txt des résultats $hFileOpen = FileOpen(@scriptdir & "\Fichiers.txt", 1) FileWriteLine($hFileOpen, "################################################") FileWriteLine($hFileOpen, _NowDate() & " " & _NowTime(3)) FileWriteLine($hFileOpen, "Fichier(s) "& $extensions & " d'un poids de plus de " & $poids & "Mo") ;recherche dossier par dossier While 1 $fichier = FileFindNextFile($doss) If @error Then ExitLoop ;on vérifit si le fichier retourné est un dossier if FileGetAttrib($chemin & "\" & $fichier) = "D" then ;recherche récursive dans le dossier $ar_Array = _FileListToArrayXT($chemin & "\" & $fichier, $extensions, 1, 2, 1,"Temp|TMP",1,Number($poids)) ;on parcourt les fichiers retournés et on affiche selon le filtre $trouve2=False ;Écriture du tableau dans le fichier texte si il y a eu un retour for $i = 1 to UBound($ar_Array)-1 FileWriteLine($hFileOpen, $ar_Array[$i]) $trouve2=True Next if $trouve2 = True Then FileWriteLine($hFileOpen, " ") Else FileWriteLine($hFileOpen, "Aucun fichier trouvé pour " & $fichier) FileWriteLine($hFileOpen, " ") EndIf ;on vide le tableau _ArrayDelete($ar_Array, "0-" & ubound($ar_Array)-1) EndIf WEnd FileWriteLine($hFileOpen, "################################################") FileClose($hFileOpen) msgbox(0,"","Fin extensions " & $extensions) EndIf EndIf EndIf endif Wend Else MsgBox(0, "Fichier non trouvé", "Fichier " & @scriptdir & "\Liste.txt inaccessible ou absent."&@CRLF&"Veuillez renseigner le fichier ainsi:"&@CRLF&"chemin=C:\CheminDuDossieràRechercher"&@CRLF&"poids=600"&@CRLF&"extensions=*.ext1;*.ext2;...") EndIf FileClose($file) if $trouve=False Then MsgBox(0, "Fichier vide", "Fichier " & @scriptdir & "\Liste.txt vide ou mal renseigné."&@CRLF&"Veuillez renseigner le fichier ainsi:"&@CRLF&"chemin=C:\CheminDuDossieràRechercher"&@CRLF&"poids=600"&@CRLF&"extensions=*.ext1;*.ext2;...") EndIf Func _FileListToArrayXT($sPath = @ScriptDir, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False, $sExclude = "", $iRetFormat = 1, $sSize = 0) Local $hSearchFile, $sFile, $sFileList, $sWorkPath, $sRetPath, $iRootPathLen, $iPCount, $iFCount, $fDirFlag ;[check and prepare parameters] ;--------------- If $sPath = -1 Or $sPath = Default Then $sPath = @ScriptDir ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sPath = StringRegExpReplace(StringRegExpReplace($sPath, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check that at least one path is set If $sPath = "" Then Return SetError(1, 1, "") ;----- If $sFilter = -1 Or $sFilter = Default Then $sFilter = "*" ;prepare filter ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sFilter = StringRegExpReplace(StringRegExpReplace($sFilter, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;check for invalid chars or that at least one filter is set If StringRegExp($sFilter, "[\\/><:\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "") If $bRecursive Then ;Convert $sFilter for Regular Expression $sFilter = StringRegExpReplace($sFilter, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sFilter = StringReplace($sFilter, "?", ".") $sFilter = StringReplace($sFilter, "*", ".*?") $sFilter = "(?i)\A(" & StringReplace($sFilter, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings ;$sFilter = "(?i)\A" & StringReplace($sFilter, ";", "|") & "\z" EndIf ;----- If $iRetItemType <> "1" And $iRetItemType <> "2" Then $iRetItemType = "0" ;----- If $iRetPathType <> "1" And $iRetPathType <> "2" Then $iRetPathType = "0" ;----- $bRecursive = ($bRecursive = "1") ;----- If $sExclude = -1 Or $sExclude = Default Then $sExclude = "" If $sExclude Then ;prepare $sExclude ;strip leading/trailing spaces and semi-colons, all adjacent semi-colons, and spaces surrounding semi-colons $sExclude = StringRegExpReplace(StringRegExpReplace($sExclude, "(\s*;\s*)+", ";"), "\A;|;\z", "") ;Convert $sExclude for Regular Expression $sExclude = StringRegExpReplace($sExclude, '([\Q\.+[^]$(){}=!\E])', '\\$1') $sExclude = StringReplace($sExclude, "?", ".") $sExclude = StringReplace($sExclude, "*", ".*?") $sExclude = "(?i)\A(" & StringReplace($sExclude, ";", "$|") & "$)" ;case-insensitive, convert ';' to '|', match from first char, terminate strings ;$sExclude = "(?i)\A" & StringReplace($sExclude, ";", "|") & "\z" EndIf ;----- ;If $iRetFormat <> "0" And $iRetFormat <> "2" Then $iRetFormat = "1" If Not ($iRetItemType = 0 Or $iRetItemType = 1 Or $iRetItemType = 2) Then Return SetError(3, 3, "") ;--------------- ;[/check and prepare parameters] ;--------------- Local $aPath = StringSplit($sPath, ';', 1) ;paths array Local $aFilter = StringSplit($sFilter, ';', 1) ;filters array ;--------------- If $bRecursive Then ;different handling for recursion (strategy: unfiltered search for all items and filter unwanted) If $sExclude Then ;different handling dependent on $sExclude parameter is set or not For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop $iRootPathLen = StringLen($sPath) - 1 Local $aPathStack[1024] = [1, $sPath] While $aPathStack[0] > 0 $sWorkPath = $aPathStack[$aPathStack[0]] $aPathStack[0] -= 1 ;----- $hSearchFile = FileFindFirstFile($sWorkPath & '*') If @error Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sWorkPath Case 1 ;relative path $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1) EndSwitch ;----- Switch $iRetItemType Case 1 While True ;Files only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $fDirFlag = @extended If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" ContinueLoop EndIf If StringRegExp($sFile, $sExclude) Then ContinueLoop If StringRegExp($sFile, $sFilter) Then ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case 2 While True ;Folders only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $fDirFlag = @extended If StringRegExp($sFile, $sExclude) Then ContinueLoop If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" If StringRegExp($sFile, $sFilter) Then ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf EndIf WEnd Case Else While True ;Files and Folders $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop $fDirFlag = @extended If StringRegExp($sFile, $sExclude) Then ContinueLoop If $fDirFlag Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" EndIf If StringRegExp($sFile, $sFilter) Then ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd EndSwitch ;----- WEnd FileClose($hSearchFile) Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop $iRootPathLen = StringLen($sPath) - 1 Local $aPathStack[1024] = [1, $sPath] While $aPathStack[0] > 0 $sWorkPath = $aPathStack[$aPathStack[0]] $aPathStack[0] -= 1 ;----- $hSearchFile = FileFindFirstFile($sWorkPath & '*') If @error Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sWorkPath Case 1 ;relative path $sRetPath = StringTrimLeft($sWorkPath, $iRootPathLen + 1) EndSwitch ;----- Switch $iRetItemType Case 1 While True ;Files only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" ContinueLoop EndIf If StringRegExp($sFile, $sFilter) Then ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case 2 While True ;Folders only $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" If StringRegExp($sFile, $sFilter) Then ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf EndIf WEnd Case Else While True ;Files and Folders $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then $aPathStack[0] += 1 If UBound($aPathStack) <= $aPathStack[0] Then ReDim $aPathStack[UBound($aPathStack) * 2] $aPathStack[$aPathStack[0]] = $sWorkPath & $sFile & "\" EndIf If StringRegExp($sFile, $sFilter) Then ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd EndSwitch ;----- WEnd FileClose($hSearchFile) Next ;$iPCount - next path EndIf ;If $sExclude Else ;If Not $bRecursive (strategy: filtered search for items) If $sExclude Then ;different handling dependent on $sExclude parameter is set or not For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sPath Case 1 ;relative path $sRetPath = "" EndSwitch For $iFCount = 1 To $aFilter[0] ;filter loop ;----- $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount]) If @error Then ContinueLoop ;----- Switch $iRetItemType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ContinueLoop ;bypass folder ;check for exclude files If StringRegExp($sFile, $sExclude) Then ContinueLoop ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ;bypass file ;check for exclude folder If StringRegExp($sFile, $sExclude) Then ContinueLoop ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop ;check for exclude files/folder If StringRegExp($sFile, $sExclude) Then ContinueLoop ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd EndSwitch FileClose($hSearchFile) Next ;$iFCount - next filter Next ;$iPCount - next path Else ;If Not $sExclude For $iPCount = 1 To $aPath[0] ;Path loop $sPath = StringRegExpReplace($aPath[$iPCount], "[\\/]+\z", "") & "\" ;ensure exact one trailing slash If Not FileExists($sPath) Then ContinueLoop ;----- Switch $iRetPathType Case 2 ;full path $sRetPath = $sPath Case 1 ;relative path $sRetPath = "" EndSwitch For $iFCount = 1 To $aFilter[0] ;filter loop ;----- $hSearchFile = FileFindFirstFile($sPath & $aFilter[$iFCount]) If @error Then ContinueLoop ;----- Switch $iRetItemType Case 1 ;files Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ContinueLoop ;bypass folder ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd Case 2 ;folders Only While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop If @extended Then ;bypass file ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf EndIf WEnd Case Else ;files and folders While True $sFile = FileFindNextFile($hSearchFile) If @error Then ExitLoop ;################### if ((FileGetSize($sRetPath & $sFile)/1024)/1024) > $sSize then $sFileList &= $sRetPath & $sFile & "|" EndIf WEnd EndSwitch FileClose($hSearchFile) Next ;$iFCount - next filter Next ;$iPCount - next path EndIf ;If $sExclude EndIf ;If $bRecursive ;--------------- ;set according return value If $sFileList Then Switch $iRetFormat Case 2 ;return a delimited string Return StringTrimRight($sFileList, 1) Case 0 ;return a 0-based array Return StringSplit(StringTrimRight($sFileList, 1), "|", 2) Case Else ;return a 1-based array Return StringSplit(StringTrimRight($sFileList, 1), "|", 1) EndSwitch Else Return SetError(4, 4, "") EndIf EndFunc ;==>_FileListToArrayXT Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now