Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search for files in a batch script and process those files?

Tags:

batch-file

cmd

I'm trying to do some things during the pre-build phase of a visual studio project. Specifically, I'm trying to execute some commands on all *.resx files within the project. Here is what I have but it doesn't work when the files/directory path have a space in them. How do I get around these spaces?

for /f %%a in ('dir /B /S *.resx') do echo "%%a"
like image 399
bsh152s Avatar asked Sep 19 '09 04:09

bsh152s


People also ask

What does %% mean in batch script?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

How do I run a batch file and see output?

Press the windows key + r (this opens the "run" window) Type: cmd into the text input and press enter (or click ok) Change to the directory that contains the batch file, e.g: cd c:\scripts\foo. Execute the batch file by typing it's name and pressing enter, e.g: somename.


1 Answers

You know that for can also run recursively over directories?

for /r %%x in (*.resx) do echo "%%x"

Much easier than fiddling with delimiters and saves you from running dir.

like image 163
Joey Avatar answered Oct 13 '22 14:10

Joey