The "FOR" command for a specific file?

It looks like I can use the command FORto search for wildcards such as

FOR /R %F IN (*.ASM) DO @ECHO %F

This successfully prints all .ASM files that exist somewhere in the current directory tree

However, if I search for a specific file name, this does not work at all:

FOR /R %F IN (LECTURE3_CODE.ASM) DO @ECHO %F

The output of the last command seems to print <path>\LECTURE3_CODE.ASMonce for each file that exists in the working directory tree.

Is there a way to make this command work the way I want it?

+3
source share
2 answers

Very simple:

FOR /R %f IN (*.ASM) DO (if "%~nf"=="LECTURE3_CODE" ECHO %f)

Done!

+3
source

- .

FOR /R %F IN (LECTURE3_CODE.AS?) DO @ECHO %F
+1

Source: https://habr.com/ru/post/1608553/


All Articles