qwert Posted April 27, 2017 Share Posted April 27, 2017 Here's a script that I fashioned as a front end for other processing: ; ; Script to build an array of all subdirs that contain a certain type of file ; (based on a selected starting directory in a disk drive's "tree structure") ; #include <File.au3> #include <Misc.au3> $type = "*.PDF" ; <<< SPECIFY THE FILE EXTENSION $dir = FileSelectFolder ( "Select a directory to process", "C:\") ; "List folders and subfolders within the root folder" (If path ends in \ then folders will be returned with an ending \.) $aList = _FileListToArrayRec($dir, "*", $FLTA_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) ;_ArrayDisplay($aList) ; FOR DEBUG, ONLY If IsArray($aList) Then For $a = $aList[0] To 1 Step -1 $hSearch = FileFindFirstFile($aList[$a] & "\" & $type) If $hSearch = -1 Then ; if nothing found, _ArrayDelete($aList, $a) ; get rid of the subdir entry Else FileClose($hSearch) ; close the active search handle EndIf If _IsPressed("11") Then Exit ; CTRL key lets you force an exit Next Else MsgBox(0, "Problem", "The directory could not be processed for some reason.") Exit EndIf $aList[0] = Ubound($aList) - 1 _ArrayDisplay($aList) ; THE RESULT Link to comment Share on other sites More sharing options...
InunoTaishou Posted April 27, 2017 Share Posted April 27, 2017 Confused, why not just do this? #include <Array.au3> #include <File.au3> Global $aList = _FileListToArrayRec(FileSelectFolder("Select a directory to process", "C:\"), "*.pdf", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_FASTSORT, $FLTAR_FULLPATH) _ArrayDisplay($aList) Link to comment Share on other sites More sharing options...
qwert Posted April 27, 2017 Author Share Posted April 27, 2017 I think the reason is: Your example returns an array of all found files in the path. My example returns an array of the subdirectories that contain such files. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 27, 2017 Share Posted April 27, 2017 I noticed that the code in the original post won't return the root folder that is being searched. For example if I search on the Documents folder for PDFs, it won't return the Documents folder as one of the folders containing PDFs even though there are PDFs there. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
qwert Posted April 27, 2017 Author Share Posted April 27, 2017 Interesting. Thanks for pointing that out. That escaped me because, as I mentioned, it's a front end for a process where all the content happens to be in subdirectories. I'll have to experiment with _FileListToArrayRec(). In the mean time, I suppose anyone who needs files from $dir can append it to the array before the FindFirstFile loop. Link to comment Share on other sites More sharing options...
argumentum Posted April 28, 2017 Share Posted April 28, 2017 hmmm, why not take Func _FileListToArrayRec( and add the If _IsPressed("11") Then where the "FindNextFileW" is at. All you really want to do is able to cut it short if it takes too long . Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. 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