How to Pass Multiple Files to an MS-DOS Batch Function?

I've searched like a madman but no dice ... I just wonder how you'd go about sending files from a multiple files selection as arguments to an MS-DOS-based function ...

Here's my button script. It works, but only does its thing on one file. FYI, the button's end result will convert SVG images to ICO icons.


cd {sourcepath}
SET originalFilename={file}

REM Specific to Swedish date and time locale; needs to be adjusted for other locales
SET _Year=%date:~0,4%
SET _Month=%date:~5,2%
SET _Date=%date:~8,2%
SET _Hour=%time:~0,2%
SET _Minute=%time:~3,2%
SET _Sec=%time:~6,2%
SET _MSec=%time:~9,3%
SET timeStamp=%_Year%%_Month%%_Date%%_Hour%%_Minute%%_Sec%%_MSec%
SET newFilename=%originalFilename%_%timeStamp%.ico

REM Requires ImageMagick to be installed
C:\Portable\ImageMagick\magick.exe convert -background none {file} -define icon:auto-resize %newFilename%

Posting my horrible attempts would just be sickening, so I'll spare your eyes.

Here's the button: SVG → ICO.dcf (1.8 KB)

When multiple files are selected and you use a single-file code like {file}, the line that code is part of will be repeated once for each selected file, before any subsequent lines.

So in this case, the batch file will effectively set the newFilename env-var for the last file, then run magick.exe on every file with the last file's newFilename as the target, which isn't what you want.

You could make this work by moving the batch code into a .bat file and running that from an Opus button, so the whole .bat file is run once per file.

If it was me, I would use scripting instead, as that can do the filename / date / time manipulation better and doesn't have all the shortcomings of DOS batch (e.g. poor Unicode support, and issues with certain characters in filenames), and then you can loop through the selected files and run commands on them however you need to.

I would expect this to work

C:\Portable\ImageMagick\magick.exe convert -background none "{filepath}" -define icon:auto-resize "{file}_{date|yyyy_MM_dd}_{time|HH_mm_ss}.ico"

Absolutely fantastic, lxp. I'm so thankful for your help, this saves me the day not having to push the convert button for each and every file. Funny how simple the solution seems once looking at it.

For anyone interested, this is one neat button in my opinion. Converts all your selected SVG or AI files into neat little ICOs. (You need to have ImageMagick installed):

SVG → ICO.dcf (830 Bytes)