I have this code below in a batch file (Windows). It returns a list of paths for each .jpg
file in a directory. Then passes that list to the ImageMagick Convert function (not the Windows convert) to create a pdf.
echo moving CMD to drive location at %~dp1
CD /d %~dp1
echo getting the list of file names
FORFILES /p %~dp1 /s /m "*.jpg" /C "cmd /c echo @path" > files.txt
echo creating the pdf using ImageMagick
convert @files.txt test.pdf
This works fine for returning the jpg image data or another single file type. I need it to search for multiple image file types and I have seen this example solution where you can put the FORFILES
into a FOR
loop.
for %%G in ( .jpg , .tif ) do FORFILES /p %~dp1 /s /m "*.jpg" /C "cmd /c echo @path" > files.txt
But if I do that the program is no longer recursive. The /s
in forfiles
no longer works.
I have tried FOR /R
but it doesn't handle folder names with spaces which I need to be able to do.
Any thoughts on how to keep this recursive and not have issues with folder names with spaces?