Moving SUB-FOLDERs

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
CompuZap
Posts: 2
Joined: 14 Sep 2022 23:56

Moving SUB-FOLDERs

#1 Post by CompuZap » 15 Sep 2022 00:23

I'm having a senior moment . . .
I have many "X:\Root-Folders, each having only ONE \Sub-Folder with many files in each.
I would like to get rid of the \Root-Folders by moving all the \Subs to the \Root and then
deleting the "then" empty original \Root-Folders.

(getting old is hard to do)
Thanks
Peter

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Moving SUB-FOLDERs

#2 Post by aGerman » 15 Sep 2022 09:49

Code: Select all

for /d %%i in ("X:\*") do for /d %%j in ("%%i\*") do (
  move /-y "%%j" "X:\"
  rd "%%i"
)
I hope your sub folders have all unique names. Otherwise the MOVE command will ask you for confirmation if you want to overwrite a previously moved folder with the same name. Also, if your root folder isn't empty after moving the sub folder to X:\ the RD command will not delete it. I wrote it this way in order to protect you from losing data.

Steffen

CompuZap
Posts: 2
Joined: 14 Sep 2022 23:56

Re: Moving SUB-FOLDERs

#3 Post by CompuZap » 15 Sep 2022 11:59

Thank you very much Steffen.
With a slight modification to your code, it worked perfectly.
I had made a mistake in my description. What I had was ...
X:\Root_Folders\Unwanted_Folders\Keeper_Folders\Files.
I needed to "move" all the Keeper Folders into their Root Folders.
All's well now. Thanks again.
Peter

Post Reply