Please look at the following scenario wherein a folder A
has many subfolders with different names. These subfolders have n
number of .jpg
files, which I am trying to scale and crop.
Folder A\ SubFolder 01\*.jpg SubFolder 02\*.jpg . . . SubFolder xx\*.jpg
These sub-folders are with different names and do not have a trend when it comes to its names.
I have created a batch file which would scale and crop images. This is working perfectly. I need to run the following command (name of file: ScaleCrop.bat) in each SubFolder xx:
for %%I in (.) do set CurrDirName=%%~nxI
for %%a in ("*.JPG") do ffmpeg -i "%%a" -vf ^"scale=-1:260, crop=250:250^""..\ScaledImages\%CurrDirName%\%%a.JPG"
for %%a in ("*.JPG") do ffmpeg -i "%%a" -vf ^"scale=260:-1, crop=250:250^""..\ScaledImages\%CurrDirName%\%%a.JPG"
pause
The command Scales and crops the image in the folder and saves these files in to a folder named SacledImages
, which too has subfolders of the same name (SubFolder 01
, SubFolder 02
,…,SubFolderxx
).
I have created another .bat
file which I used to copy ScaleCrop.bat
to each subfolder.
for /d %%a in ("C:\Users\Name\Desktop\Folder A\*") do copy " C:\Users\Name\Desktop\Folder A\ScaleCrop.bat""%%a"
How could I code a batch file run and execute ScaleCrop.bat
from each of these subfolders?
I tried using the following code, but this just calls the .bat file
inside each subfolder, however it is not executing:
for /f %%f in ('dir /ad /b') do start %%f\ScaleCrop.bat
I Tried the following as well, this does the trick, but all images are getting overwritten as the scaled-cropped images are saved on to /SacledImages
Folder and not inside ScaledImages/SubFolderxx
:
for /r "C:\ Users\Name\Desktop\Folder A " %%a in (.) do ( pushd %%a
for %%I in (.) do set CurrDirName=%%~nxI
for %%a in ("*.JPG") do ffmpeg -i "%%a" -vf ^"scale=-1:260, crop=250:250^""..\ScaledImages\%CurrDirName%\%%a.JPG"
for %%a in ("*.JPG") do ffmpeg -i "%%a" -vf ^"scale=260:-1, crop=250:250^""..\ScaledImages\%CurrDirName%\%%a.JPG"
pause popd )