Windows commandline: move all subfolders' contents to parent
You can't do a move * ..
for directories. The only way for move
to move a directory is to specify the directory name itself (no wildcards allowed). So you need a second loop (within the first) to loop through the directories:
@echo off
for /d %%d in ("*") do (
for /d %%e in ("%%d\*") do (
move "%%e" .
)
)
No need for pushd
because you can move it from the parent to the parent.
note: this is used for a batch file so for the %d
the %
is doubled to %%d
and %%e
. If you run it directly from the prompt you only need one %
.
Edit:
If the first-level subfolders (Subfolder1 and Subfolder2) also contain files (besides folders Stuff1 and Stuff2) you can add another move to the outer for.
@echo off
for /d %%d in ("*") do (
for /d %%e in ("%%d\*") do (
move "%%e" .
)
move "%%d\*" .
)