Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"FOR" command for a specific file?

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?

like image 421
Govind Parmar Avatar asked Nov 19 '25 01:11

Govind Parmar


2 Answers

Very simple:

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

Done!

like image 59
Monacraft Avatar answered Nov 22 '25 03:11

Monacraft


This will work for your original line - the wildcard is the key here.

FOR /R %F IN (LECTURE3_CODE.AS?) DO @ECHO %F
like image 42
foxidrive Avatar answered Nov 22 '25 02:11

foxidrive



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!