A little help with a DOS batch file *solved*

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
I wrote a batch file that uses ImageMagick to make thumbnail images.

@echo off

IF NOT EXIST thumbnails mkdir thumbnails

for /F %%i in ('dir /b /A-D *.jpg') do IF NOT EXIST thumbnails\%%i (
echo Creating thumbnail for %%i...
convert +profile "*" -quality 75 %%i -resize 95x71 thumbnails\%%i
echo Done.)

This seems to only work when the image filename does not have any spaces in it. If it has spaces, it'll input up to the space. Anyone know how to get it to take the full filename, including spaces? Thanks.
 

Smilin

Diamond Member
Mar 4, 2002
7,357
0
0
You're gonna need quotes in there somewhere, the tricky part might be WHERE!

I'd start with putting them around any instance of "%%i"

If %%i is part of a path put quotes around the whole path "thumbnails\%%i"

 

Smilin

Diamond Member
Mar 4, 2002
7,357
0
0
another thought...

use the shortnames to do this perhaps? check switches in the DIR command, I think it's /x or something.
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Originally posted by: Smilin
another thought...

use the shortnames to do this perhaps? check switches in the DIR command, I think it's /x or something.

Thanks for the suggestions, but it seems that the /x switch can't be used with /b. "dir /x /b" will return the same thing as "dir /b".

I also tried the quotes in every instance of %%i, but that didn't work either. I tried both single and double quotes. The batch file would quit immediately after hitting a quoted %%i.
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
I got it. I had to replace the delimiter set in the FOR loop with something other than spaces and tabs. I used a / since that's an illegal filename character.