millisys Posted July 17, 2021 Share Posted July 17, 2021 Hello everyone. thank you for reading this post. I m trying to use _FileListToArrayRec to search "c:\files" for PDF files only residing within subdirectories beginning with the word "batch". I have tried the following syntaxes and am not having success. Would someone be kind enough to point me in the right direction? Thank you. $aFiles = _FileListToArrayRec("c:\files\batch*", "*.pdf||", 1, 1, 1, 2) $aFiles = _FileListToArrayRec("c:\files", "batch*;*.pdf||", 1, 1, 1, 2) $aFiles = _FileListToArrayRec("c:\files", "batch*.*pdf||", 1, 1, 1, 2) Link to comment Share on other sites More sharing options...
pseakins Posted July 17, 2021 Share Posted July 17, 2021 (edited) This works. $aFiles will be changed for each target folder but you should be able to work with this. You could have a separate array for each iteration, or figure a way to concatenate all the results. #include <File.au3> #include <Array.au3> $aFolders = _FileListToArrayRec("C:\files", "batch*", 2) If @error Then Exit _ArrayDisplay($aFolders) For $i = 1 To $aFolders[0] $aFiles = _FileListToArrayRec("C:\files\" & $aFolders[$i], "*.pdf") If @error Then ContinueLoop _ArrayDisplay($aFiles) Next Edited July 18, 2021 by pseakins Edit1: Posted code in lieu of concept. Edit2: Removed code breaking debug statements Phil Seakins Link to comment Share on other sites More sharing options...
Musashi Posted July 17, 2021 Share Posted July 17, 2021 (edited) 10 hours ago, pseakins said: [...] $aFolders = _FileListToArrayRec("C:\files", "batch*", 2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $aFolders=[' & $aFolders & '] Error code: ' & @error & @CRLF) ;### Debug Console If @error Then Exit [...] Caution : The ConsoleWrite function (re)sets the @error macro to 0 (not explicitly specified in the help). So if _FileListToArrayRec returns non-0 , it will be overwritten by ConsoleWrite , and If @error Then Exit will not be triggered. Try it with e.g. an invalid path and : [...] If @error Then ConsoleWrite("Error found => Exit" & @CRLF) Exit Else ConsoleWrite("no Error found => Continue" & @CRLF) EndIf [...] Macros like @error or @extended should sometimes be better saved in variables : #include <File.au3> #include <Array.au3> Local $sBaseDir = @ScriptDir & "\TestDir", $iError, $iExtended $aFolders = _FileListToArrayRec($sBaseDir, "*", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) $iError = @error $iExtended = @extended ConsoleWrite('@@ Debug : Error code = ' & $iError & ' Extended = ' & $iExtended & @CRLF) ; *** Debug If $iError Then ConsoleWrite("!Error found => Exit" & @CRLF) Exit Else ConsoleWrite("no Error found => Continue" & @CRLF) EndIf _ArrayDisplay($aFolders) Edited July 17, 2021 by Musashi Reworded "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
Musashi Posted July 17, 2021 Share Posted July 17, 2021 (edited) 6 hours ago, millisys said: I'm trying to use _FileListToArrayRec to search "c:\files" for PDF files only residing within subdirectories beginning with the word "batch". Provides an array ($aFiles) which contains all PDF files which occur in directories named Batch*. #include <File.au3> #include <Array.au3> Local $sBaseDir = "c:\files", $aFolders[0], $aFiles[0], $aArr[0] $aFolders = _FileListToArrayRec($sBaseDir, "Batch*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If @error Then Exit MsgBox(BitOR(4096, 16), "Message : ", "Error or no folders found" & @CRLF) For $i = 1 To $aFolders[0] $aArr = _FileListToArrayRec($aFolders[$i], "*.pdf", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If Not @error Then For $k = 1 To $aArr[0] _ArrayAdd($aFiles, $aArr[$k]) Next EndIf Next _ArrayDisplay($aFiles, "matching pdf-files :") Edited July 17, 2021 by Musashi typo FrancescoDiMuro 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
pseakins Posted July 18, 2021 Share Posted July 18, 2021 19 hours ago, Musashi said: Caution : The ConsoleWrite function (re)sets the @error macro to 0 Thanks @Musashi, I was well aware of this. I should have removed the debug statements before posting but I thought I would leave them in thinking they might help while overlooking the fact that the first one would break the following statement. They are not even useful anyway as the array (as a whole) can't be displayed in a consolewrite statement. Phil Seakins Link to comment Share on other sites More sharing options...
Musashi Posted July 18, 2021 Share Posted July 18, 2021 2 hours ago, pseakins said: Thanks @Musashi, I was well aware of this. It would have been a great surprise to me, if it were otherwise . The hint was directed to our (no reaction showing) user @millisys . "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
millisys Posted July 22, 2021 Author Share Posted July 22, 2021 Thanky you pseakins and Musashi for you help with this. pseakins 1 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