Page 1 of 1

Moving SUB-FOLDERs

Posted: 15 Sep 2022 00:23
by CompuZap
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

Re: Moving SUB-FOLDERs

Posted: 15 Sep 2022 09:49
by aGerman

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

Re: Moving SUB-FOLDERs

Posted: 15 Sep 2022 11:59
by CompuZap
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