How can I replace %%f in a Windows batch file with a quoted string?

I've done some initial searches here and couldn't find an answer that quite fits what I am trying to do here. I have basically inherited this batch script to handle a specific process of copying / moving / manipulating a set of files, and it was recently brought up that it does not work if the batch file is run from a directory that has spaces in it. I've narrowed the problem down to the following block, and cannot find the right way to replace it:

for /r %%f in (*.ext1) do (
  echo %%f
  my_tool.exe %%f %%f.ext2
  del /f /q %%f

So basically what should happen here is, my_tool takes two parameters, an input file and an output file. It does some processing to the input file, and outputs it as the same file, but with an additional .ext2 extension to it. (foo.ext1 becomes foo.ext1.ext2)

The problem is that %%f does not quote the fully qualified path to the file, so the tool is getting more parameters than it is expecting, and not in the proper formatting. Any suggestions would be greatly appreciated.


Put paramenters in double quotes, so batch will transmit them to your tool as 2 paramenters:

for /r %%f in (*.ext1) do (
  echo "%%f"
  my_tool.exe "%%f" "%%f.ext2"
  del /f /q "%%f"

Need Your Help

Get results from two tables - Server 2008R2 sql-server table-relationships

I have a search form with 2 fields(first name and last name) from one table (Just has person's information) and 4 (Incident number, date, place, created by) from the other (has one or more incident...

Custom UIView transitions

ios uiview core-animation

I am implementing a slide show which will change images using custom animations. This is link of transitions. Is it possible to implement