Batch create a Folder in every subfolders and Move all the .jpg files in it
I made this batch file that makes a folder named Pictures and puts all the .jpg files in it.
@echo off md Pictures for %%i in ("*.jpg") do ( move /Y "%%i" "Pictures" ) end
Is there anyway to make the script iterate through subdirectories as well? I want to run the batch file on a root directory and make it work for all subfolders.
Actually I just figured it out
@echo off setlocal for /f "usebackq tokens=*" %%a in (`dir /b /a:d`) do ( rem enter the directory pushd %%a echo In Directory: %%a md Pictures for %%i in ("*.jpg") do ( move /Y "%%i" "Pictures" ) rem leave the directory popd ) endlocal
It does the same thing but it works through subfolders. Took me sometime to figure it out. Anyway, hopefully it'll help others too.
Based upon the answer you've supplied, I would suggest you could do that like this, in a single line batch-file:
@For /D %%G In (*) Do @"%__AppDir__%Robocopy.exe" "%%G" "%%G\Pictures" *.jpg /Mov >NUL 2>&1
As an alternative, because
For /Dmay not pick up all of your directories, (it ignores directories with the hidden and system attributes):
@For /F "EOL=? Delims=" %%G In ('Dir /B /AD') Do @"%__AppDir__%Robocopy.exe" "%%G" "%%G\Pictures" *.jpg /Mov >NUL 2>&1
for /f %%a in ('dir /b /ad "Filepath"') do ( md "%%~fa\Pictures" for %%b in ("*.jpg") do robocopy "%%~fb" "%%~fa\Pictures\" /mov )