MyDisplayNameGoesHere

How to loop folders, and move files, on conditions?

4 posts in this topic

Thank you for taking the time to read this. I have spent many hours, and time on Google looking for a solution.
I have a directory like below.
Folder1
  SubFolder1
  SubFolder2
  SubFolder3
Folder2
  SubFolder1
  SubFolder2
Folder3
  SubFolder1

[The cake]
What I really need help with is 'Folder3'. I need to move the all the files from the 'Subfolder' to the Parent folder (Folder 3).  Basically just move the files up a folder. Just on Folders that have only '1' Subfolder. Ignore any that have more then 1 'Subfolder'.
[Ice cream on the cake]
Can the folders be moved once it is done, to a different directory?
[Chocolate sauce on the Ice cream on the cake]
After all of the is done, how to move all the files from 'Subfolders', to the "parent folder'.
I can get this to kinda work with with command line 'For /r %G etc'.
I have tried Robocopy. xxcopy, powershell, and other assorted things. The command line works decently, but only on on one folder. I can not get it to loop. When it does loop, it gets messy :)
This seems like it would not be hard. I tired lots of ideas form 'http://superuser.com', and 'http://serverfault.com'. Most of them kinda sorta worked. Though they only worked on one folder. I need one that can loop through a bunch.
I understand simple stuff with Autoit. I have a feeling this will involve arrays with looping, I have no clue how to do 'all that'.
Any help and/or pointers are appreciated.
Thank you.
 

Share this post


Link to post
Share on other sites



@MyDisplayNameGoesHere can you please clarify a bit? Correct me if wrong on these bullet points:

  • Cake
    • In Folder 3 only, any files in SubFolder 1 you want moved to the parent folder.
    • "Just on folders that only have 1 subfolder" - I don't understand this, as you state you need help only with Folder 3
  •  Ice Cream
    • If you are asking can the subfolder (now emptied of files) be moved to another folder, the answer is yes
  •  Chocolate Sauce
    • Are you now asking to move all files from all subfolders to their parent folder?

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

@JLogan3o13

You have valid points. I have been messing with this for over a week now, so my thoughts are a little screwed up:)
I have a Folder with a lot of Subfolders. Their are numerous Subfolders that have Subfolders. Some have multiple Subfolders, some only have one Subfolder. In the folders that only have one Subfolder I would like to move the contents up to its parent sub folder. Then move those folders that got 'fixed' to another drive.

Then pause as I something else.

Then on the remaining folders, move their contents to their respective parent folders.
Thank you for asking about it. I'm sure I made it clear as mud :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

 

If you're looking to copy files from sub folders to main folder or vice versa then maybe what I have below will solve your problem. 

So basically you want to create your 4 variables that store the path of each of these folders. The script below only has the main path and sub1 folder. So you need to add sub 2 and 3. Change sub number to [2] or [3]. If you have sub folders in another sub folder than do "\Sub 1\Sub 2\".

Since the script is in the folder you can use the @scriptdir and list the sub directories like below.. I'll include the dircopy help folder if this is what you're looking to do.

Everything in sub1 folder is copied to MainPath foder

$MainPath = @ScriptDir & "\"
$sub1= @ScriptDir & "\Sub 1\"
If DirCopy($sub1,$MainPath,1) ; Optional Then DirRemove($sub1,1)

;Comments
;$Sub1 folder is the [source dir]
;$MainPath folder is the [dest dir] 
;The number (1) is set to overwrite.. see the two options below
;DirCopy ( "source dir", "dest dir" [, flag = 0] )

;[optional] this flag determines whether to overwrite files if they already exist:
;$FC_NOOVERWRITE (0) = (default) do not overwrite existing files
;$FC_OVERWRITE (1) = overwrite existing files

pic 1.png

Dircopy help folder

https://www.autoitscript.com/autoit3/docs/functions/DirCopy.htm

Edited by aa2zz6
Spelling errors are hard to leave alone :|

Share this post


Link to post
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