Jump to content

Copy only the files from parent folder and subfolder


 Share

Recommended Posts

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

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 by AutoBert
Link to comment
Share on other sites

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])
Next

If that doesnt suite your needs feel free to ask

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

  • Moderators

Tech63,

What version of AutoIt are you running?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Tech63,

You need to upgrade - the recursive file search function was only added in 3.3.10.0.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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])
Next

If you need more help feel free to ask

Edited 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

  • Moderators

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])
Next

That 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Tech63,

Glad we could help.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...