0

I'm trying to make a very simple .bat using imagemagick to make icons that you can just drag and drop any image onto the .bat to run it. small example is

convert "%~1" -resize 256x256^^! "%~n1".ico

%~1 to take the full file and path dropped on and %~n1 to get that filename and use it for the .ico it ouputs.

Since any file can be dragged on to do it, how would i deal with wild filenames that have characters that need escaping in them, like if some monster dragged in a file named ^%!!test test,0,5$5%.jpg it really messes it up. Is this just something thats a part of .bat life and unavoidable or can i preemptive strike and escape everything you could throw at it?

My eventual goal is to batch convert lots of random files so filenames may have any possibilities.

  • possible duplicate of https://stackoverflow.com/questions/4200316/how-to-receive-even-the-strangest-command-line-parameters – ScriptKidd Apr 19 '20 at 04:59
  • `^%!!test test,0,5$5%.jpg` is no problem as long as the file name is passed enclosed in `"` and all references to the batch file argument (file name) are also enclosed in `"` as it is the case for the single line posted and [delayed expansion](https://ss64.com/nt/delayedexpansion.html) is __not__ enabled. I don't see any reason on the single command line to enable delayed environment variable expansion. Why do you use `256x256^^!` instead of just `256x256!` on command line? Have you enabled delayed expansion? Yes, why? Show us the code which requires delayed expansion. – Mofi Apr 19 '20 at 08:01
  • clearing delayed expansion got it to accept any filename so that helped!, but it still doesnt like not having the double ^^! over ! for whatever reason, it might be due to imagemagick. its working now regardles file name so thanks! – luminousfox Apr 19 '20 at 13:26

0 Answers0