“FOR”命令为特定文件? [英] "FOR" command for a specific file?
问题描述
似乎我可以使用 FOR
命令递归搜索通配符,例如
FOR / R%F IN(* .ASM)DO @ECHO%F
这将成功打印所有带有.ASM
但是,如果我正在搜索一个特定的文件名,这根本不起作用:
FOR / R%F IN(LECTURE3_CODE.ASM)DO @ECHO%F
后一个命令的输出似乎为工作目录树中存在的每个文件打印一次< path> \LECTURE3_CODE.ASM
有没有办法让这个命令按照我想要的方式工作?
很简单:
FOR / R%f IN(* .ASM) DO(if%〜nf==LECTURE3_CODEECHO%f)
Seems like I can use the FOR
command recursively to search for wildcards such as
FOR /R %F IN (*.ASM) DO @ECHO %F
This successfully prints out all files with the .ASM extension that exist somewhere within the current directory tree
However, if I'm searching for a specific filename, this doesn't work at all:
FOR /R %F IN (LECTURE3_CODE.ASM) DO @ECHO %F
The output of the latter command seems to print out <path>\LECTURE3_CODE.ASM
once for every single file that exists in the working directory tree.
Is there some way to get this command to work the way I want it to?
Very simple:
FOR /R %f IN (*.ASM) DO (if "%~nf"=="LECTURE3_CODE" ECHO %f)
Done!
这篇关于“FOR”命令为特定文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!