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

标签 windows shell batch-file cmd dos

我需要做的是从 %%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
)

最佳答案

使用 %%~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 变量修饰符(如 %%~nf)的完整列表,请从命令行运行 for/?,或在线查看 here .

关于windows - 命令行 - 如何仅在使用 for 命令循环时提取文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3120998/

相关文章:

java - 错误启动 jetty 服务 (Solr)

c++ - 在 QtCreator (VS 2010) 中设置 CUDA v7.0

linux - fping 主机列表返回错误值

linux - 如何使用 cURL 从文件中读取标题?

batch-file - 批处理文件 - 需要 7-zip 的替代方案 - 无法移动

c# - 从十六进制数获取 Windows 系统错误代码标题/描述

regex - [[ :upper:]] and [:upper:] (bash)? 之间有什么区别

windows - 批量更改 PATH

c++ - ShellExecute:Verb "runas"不适用于路径中包含空格的批处理文件

java - 检测用 Java 读取的文件