Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file for loop with spaces in dir name

How do I modify this:

for /f %%a IN ('dir /b /s build\release\*.dll') do echo "%%a" 

to work when the path contains spaces?

For example, if this is run from

c:\my folder with spaces 

it will echo:

c:\my 

Thanks

like image 976
Andrew Bullock Avatar asked Apr 05 '11 13:04

Andrew Bullock


People also ask

How do you handle a space in a batch file?

When you send arguments, those with poison or space characters need to be doublequoted. Inside your batch file, if you no longer need the surrounding doublequotes, you'd remove them by using %~5 instead of %5 . Additionally the recommended syntax for the set command is Set "VariableName=VariableValue" .

What does %% mean in batch files?

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.

What does %1 mean in a batch file?

When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.


1 Answers

You need to use:

for /f "delims=" %%a IN ('dir /b /s build\release\*.dll') do echo "%%a"

This overrides the default delimiters which are TAB and SPACE

like image 85
Jan Zyka Avatar answered Sep 28 '22 04:09

Jan Zyka