windows 命令行 - 如何仅在使用 for 命令循环时提取文件名

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3120998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:43:13  来源:igfitidea点击:

Command Line - how to extract a file name only when using a for command loop

windowsshellbatch-filecmddos

提问by Brandon Michael Hunter

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

我需要做的是从 %%f 中提取文件名,以便我可以创建正确的 dll 名称。

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
)

采纳答案by Josh Kelley

Use %%~nf.

使用 %%~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 variable modifiers like %%~nf, run for /?from the command line, or look online here.

有关 %%~nf 等 FOR 变量修饰符的完整列表,请从命令行运行for /?,或在此处在线查看