1

I trying to write a batch file that recursively goes through the directories (taking into account spaces as well) and performs an ImageMagick command. I have the following:

for /R %%a IN (*.png) do mogrify %%a -fuzz 0% -transparent none

Note: this gets stuck with spaces.

I also tried this:

for /R "tokens=*" %%a IN (*.png) do mogrify %%a -fuzz 0% -transparent none

Note: this version doesn't spit an error, but does not modify the contents of the folder.

Any help is appreciated. Kind regards, Alex

Mark
  • 3,609
  • 1
  • 22
  • 33
  • Mistype^^^ for /R "tokens=*" %%a IN (.png) do mogrify %%a -fuzz 0% -transparent none – user2993590 Nov 14 '13 at 19:19
  • Similar - but I am trying not to specify the directories. I am also using the ImageMagic commands. – user2993590 Nov 14 '13 at 19:42
  • The information is there in those answers. Read them, and see how they apply to your own code. The second one, for instance, uses an `echo` in the `for` loop to output the file name from a `dir` listing; that example applies **directly** to your question here. – Ken White Nov 14 '13 at 19:45
  • Seriously consider using Powershell for this. It will not have the same problems with spaces, and its looping constructs are much simpler: `Get-ChildItem *.png | ForEach-Object { mogrify $_ -fuzz 0% -transparent none }` or even shorter: `ls *.png | % { mogrify $_ fuzz 0% -transparent none }` – bonsaiviking Nov 14 '13 at 19:46

1 Answers1

1
for /R %%a IN (*.png) do mogrify "%%~fa" -fuzz 0%% -transparent none

Please note the double percent signs in 0%%.

Endoro
  • 37,015
  • 8
  • 50
  • 63