I’m trying to create a batch file that will run Doug Cockford’s JSMin against all the .js files in a directory. Here’s what i’ve got:
for /f %%a IN ('dir /b /s *.js') do jsmin <%%a >%%~da%%~pamin\%%~na.min%%~xa
The problem is that the angle brackets (<>) cause the batch file to interpret it as 0< and 1>. Event running just:
jsmin <scripts\script.js >jsmin-stuff.js
in a batch file does the same thing. Escaping the angle brackets with ^ makes jsmin think that the angle brackets are part of the path.
Any ideas? What am I doing wrong?
First of all, you are using
for /ffor something whereforalone is sufficient. Secondly, I don’t recommend doing this recursively, as you are obviously placing the min-ified scripts into a subfolder of the same tree.(from the command line, not from a batch) does what it should for me here. What you are seeing with
0<and1>is actually correct, as 0 is the standard input stream and 1 the standard output stream, which you are both redirecting.For doing this recursively the following line did the trick for me:
ETA: Ok, I checked it, the
dirmethod works in fact more reliable than usingfor /r. I apologize. From a batch file the following worked for me:for /falways does tokenizing, usually only based on whitespace, though. But my profile folder already has whitespace in it, so better turn off tokenizing altogether.