0

I'm looking to make a batch script that will move all images in sub subfolders down to the layer above the batch script. For Example:

comics\move.bat

comics\series 000\series 000 blah\01.jpg,02.jpg, etc.

comics\series 001\series 001 blah\series blah\01.jpg,02.jpg, etc.

into

comics\series 000\01.jpg,02.jpg, etc.

comics\series 001\01.jpg,02.jpg, etc.

I've tried several variations of for /r %%i in (*.jpg) do move "%%~fi" "%%~pi*.jpg"

But it won't do anything. One way I had it would move all images into the same folder as I was running the script from but that's the closest I've gotten. A clean up of the now empty folders would be nice too!

Dracrius
  • 7
  • 1
  • 1
  • 7

3 Answers3

0

Create a .bat file with following content on the root folder and double click it.

@echo off
for /f "usebackq tokens=*" %%d in (`dir /s /b /o:n /ad`) do (
  cd "%%d"
  for /f "usebackq tokens=*" %%f in (`dir /b /o:n /a-d`) do (
    move /y "%%f" ..
  )
)
pause

To explain the code, the outer loop iterates directories recursively and cd into it. The inner loop iterates all files inside the directory and move it one up above. /y flag on move is to suppress prompting. Use dir /? for explanation of all the dir flags. As for the for part I took it from https://stackoverflow.com/a/2768660/179630

Community
  • 1
  • 1
gerrytan
  • 40,313
  • 9
  • 84
  • 99
  • This is going to shuffle all files up a folder level, rather than move all files into one folder, right? I think the title is misleading because the question and example asks to move all files in a branch into one folder. – foxidrive Feb 21 '14 at 14:45
  • Now the question has been edited it looks very different :). I'll fix my answer some time soon. – gerrytan Feb 21 '14 at 16:43
0

This should move the images in each branch into the first level folder, but doesn't deal with filename collisions.

Test it on a folder of copies of your files.

@echo off
for /d %%a in (*) do (
    pushd "%%a"
        for /r %%b in (*.jpg) do move "%%b" . 
    popd
)
pause
for /L %%a in (1,1,5) do for /d /r %%b in (*) do rd "%%b" 2>nul

The last line should remove only empty folders up to 5 levels deep, if they exist.

foxidrive
  • 40,353
  • 10
  • 53
  • 68
-2

Try this:

move comics\series 000\series 000 blah\*.jpg comics\series 000
jesy2013
  • 319
  • 2
  • 12