I'm trying to find files in a folder with specific pattern like:
abcd201 abcd001 abcd004
The folder contains files named
abcd(3 numbers)
I'm trying to use the pattern:
abcd[0,2][0][1,4]
but currently not working.
DIR /b C:\Folder\abcd"[0,2][0][1,4]".txt
Thanks!
dir
command does not support regular expressions. You need to filter the output with findstr
dir /b "c:\folder\abcd*.txt" | findstr /r /c:"^abcd[02]0[14]\.txt$"
That is, use dir command to obtain a first approximation of what you are searching and then filter the list (pipe the dir
command to findstr
) to obtain only the list of required files.
The regular expression (/r
) in findstr
means: filter the lines, starting at the start of the line (initial ^
), followed by abcd
, followed by any character in the set [02]
, followed by a 0
, followed by any character in the set [14]
, followed by a dot (a single dot means any character, so, it needs to be escaped \.
), followed by the string txt
and the end of the line ($
).
Maybe you will need to add a /i
switch to findstr to indicate it must ignore case when matching.