Tech63 Posted August 27, 2015 Share Posted August 27, 2015 Scenario: I have a scans folder on my server, When i scan from my multifunction scanner to my "scans" folder on the server it makes a bunch of random subfolders under the "scans" directory that contain the scanned images .jpg. Ideally i need only the .jpg files on the root of the "scans" folder and not all of the subfolders. Is there a way i can copy only the files(.jpg) of all subfolders (subfolders have random names such as "image-0023445845") back to the root of the "scans" directory and remove the subfolders that were created? Link to comment Share on other sites More sharing options...
AutoBert Posted August 27, 2015 Share Posted August 27, 2015 (edited) Use _FileListToArrayRec with $FLTAR_FILES for the 3. Param ($iReturn). After copying each file (filecopy) of the returned array you can remove the subfolder's using _FileListToArrayRec a 2. time and remove from the 2. item to the end of the array. Edited August 27, 2015 by AutoBert Link to comment Share on other sites More sharing options...
Surya Posted August 27, 2015 Share Posted August 27, 2015 Try this code:#include <FileConstants.au3> #include <Array.au3> #include <File.au3> ;$rootdir = "F:\scans" $rootdir = "F:\Software" $simplist = _FileListToArray($rootdir, "*.jpg",$FLTA_FILES,True) For $i = 1 To $simplist[0] FileMove ($simplist[$i],$rootdir &"\image-" &$i &".jpg") Next $full = _FileListToArrayRec($rootdir,"*.jpg" ,$FLTAR_FILES , $FLTAR_RECUR,$FLTAR_NOSORT,$FLTAR_FULLPATH) For $i = 1 To $full[0] FileCopy ($full[$i],$rootdir &"\image-" &$i + $simplist[0] &".jpg") Next $folders = _FileListToArrayRec ($rootdir,"*", $FLTAR_FOLDERS , $FLTAR_RECUR ,$FLTAR_NOSORT ,$FLTAR_FULLPATH) For $i = 1 To $folders[0] If Not StringCompare($folders[$i],$rootdir) = 0 Then FileDelete($folders[$i]) NextIf that doesnt suite your needs feel free to ask Tech63 1 No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Tech63 Posted August 27, 2015 Author Share Posted August 27, 2015 Surya, I changed $rootdir to the correct path, when i try to run i get an error. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 27, 2015 Moderators Share Posted August 27, 2015 Tech63,What version of AutoIt are you running?M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tech63 Posted August 27, 2015 Author Share Posted August 27, 2015 3.3.8.1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 27, 2015 Moderators Share Posted August 27, 2015 Tech63,You need to upgrade - the recursive file search function was only added in 3.3.10.0.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tech63 Posted August 27, 2015 Author Share Posted August 27, 2015 Thanks! upgraded and ran the script. The files move to the root folder correctly, but the empty folders still exist. Link to comment Share on other sites More sharing options...
Surya Posted August 27, 2015 Share Posted August 27, 2015 (edited) run this :#include <file.au3> #include <FileConstants.au3> $rootdir = "F:\Software\" ;You have to add "\" after the directory i forgot that before $folders = _FileListToArrayRec ($rootdir,"*", $FLTAR_FOLDERS , $FLTAR_RECUR ,$FLTAR_NOSORT ,$FLTAR_FULLPATH) For $i = 1 To $folders[0] If Not StringCompare($folders[$i],$rootdir) = 0 Then DirRemove($folders[$i]) NextIf you need more help feel free to ask Edited August 27, 2015 by Surya No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 27, 2015 Moderators Share Posted August 27, 2015 Tech63,Hardly surprising - you need DirRemove to delete folders, not FileDelete. Try replacing the last loop with this (not tested):$folders = _FileListToArrayRec ($rootdir, "*", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) For $i = $folders[0] To 1 Step -1 DirRemove($folders[$i]) NextThat should work unless the folders still contain files, in which case you will need to set the additional parameter as explained in the Help file.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Tech63 Posted August 27, 2015 Author Share Posted August 27, 2015 Thanks for the code! This is now working as needed! You guys saved me tons of time. Can't thank you enough! Link to comment Share on other sites More sharing options...
Surya Posted August 27, 2015 Share Posted August 27, 2015 you are always welcome feel free to ask for more help No matter whatever the challenge maybe control on the outcome its on you its always have been. MY UDF: Transpond UDF (Sent vriables to Programs) , Utter UDF (Speech Recognition) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 27, 2015 Moderators Share Posted August 27, 2015 Tech63,Glad we could help.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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