I have a series of file in a folder and I want to check if a specific string is in one of the file name. I was looking at findstr command but I think it only looks at the content of the file.
Its like find "hold" in the file name holdings092516.txt should return true. I am a bit new to dos commands so I hope someone can help me.
Finding a substring in a file name
Moderator: DosItHelp
Re: Finding a substring in a file name
Either:
or:should work fine.
Code: Select all
dir/b mydir\*.txt|find/i "hold"
or:
Code: Select all
dir/b mydir\*.txt|findstr/i "hold"
-
- Posts: 5
- Joined: 28 Jan 2016 09:06
Re: Finding a substring in a file name
Thank you for the response.
I notice that it was returning the filename back if part of the string is found. Is their a way to determine the output by yes or no?
I notice that it was returning the filename back if part of the string is found. Is their a way to determine the output by yes or no?
Re: Finding a substring in a file name
You could always use the where command:Or even search directly for the string in your dir command:
Code: Select all
Where /Q "%UserProfile%\Documents" *hold* >Nul 2>&1
If %ErrorLevel%==1 (Echo=No) Else (Echo=Yes)
Code: Select all
Dir/A-D "%UserProfile%\Documents\*hold*" >Nul 2>&1&&(Echo=Yes)||(Echo=No)