views:

29

answers:

1

I'm trying to pass files one by one(I have to dot that since executable only accepts one file at a time). So, in my batch I have follwoing:

FOR /F %file IN ('dir /b /s *.css') DO CALL myExecutable.exe %file 

I should see out files in same directory but nothing happens, no errors are displayed either. Am I missing something here?

+1  A: 

You have several mistakes in your example:

  • FOR parameter name is a single letter only
  • CALL is used to call another batch file or a subroutine in the existing batch file, not executables
  • the FOR parameter should be referenced with two %, when in batch file
  • you need to use a non-space delimiter, if the directory you run this command in or any subdirectory, or if any of the files has a space in the name

With these in mind, here's the right command you should be using:

for /f "usebackq delims=|" %%f in (`dir /b /s *.css`) do myexecutable.exe "%%f"

Here's my answer to a similar SO question, where I give more details on using FOR to process all files in a directory.

Franci Penov
technically, you don't need the `usebackq` in your particular scenario, but it's a good habit to have.
Franci Penov
thank you this made it work. except that I had to exclude "usebackq delims=|". it didn't work, it started to process 'dir' 'b' as actual file names. once it was removed, everything works.
dev.e.loper
that's because you most probably disn't see that I actually used backquotes in my example. Also, you want to have the `delims=|`, since if you have a space in the `dir` output, it'll be tokenized by default using ` ` and only the first part will be assigned to `%%f`.
Franci Penov