Question

I want to print all the C files in a folder (including subfolders) without the path and with suffix .o \ instead of .c. So I found this command that works in cmd:

FOR /F "delims=" %a IN ('DIR /B /S *.c') DO @ECHO %~na.o \"

But when I create a bat file with this command only (one line) I get this output: ~na.o was unexpected at this time.

C:\temp>FOR /F "delims=" ~na.o \"

I undestand from the second line that it has problem with the variable %a. How should i write the above command in a batch file?

Was it helpful?

Solution

Inside a batch file you need to use two %:

FOR /F "delims=" %%a IN ('DIR /B /S *.c') DO @ECHO %%~na.o \"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top