“FOR”命令为特定文件? [英] "FOR" command for a specific file?

查看:126
本文介绍了“FOR”命令为特定文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我可以使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆