Command line - how to extract file name only when using for for loop

What I need to do is extract the file name from %% f so that I can create the correct dll name.

for %%f in (*.asmx.cs) do (
    echo %%f

    cmd /c C:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:library /r:%assemblies% %compileoptions% /out:bin/%%f.dll %%f
)
+5
source share
1 answer

Use %% ~ nf.

for %%f in (*.asmx.cs) do (
    echo %%~nf

    cmd /c C:\windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /t:library /r:%assemblies% %compileoptions% /out:bin/%%~nf.dll %%f
)

For a complete list of FOR modifiers, such as %% ~ nf, run for /?from the command line or look online here .

+5
source

All Articles