Find filenames with certain pattern on Windows command line?

Trying to find any files of certain pattern in a directory and its subdirectories. I tried:

C:\test\workspace>dir *.*.r[0-9]* /s /b
File Not Found

in hopes to find files like

abc.txt.r12222
tjy.java.r9994

Where an number is appended after the letter r, done by SVN.

What am I doing wrong?


Solution 1:

I just answered this on Stack Overflow a couple of days ago. https://stackoverflow.com/questions/15648679/find-text-string-or-part-of-text-with-dot-in-grepwin/15648872#15648872

In your case it would look like:

dir * /s/b | findstr \.r[0-9]+$

Update

The * in the one of the other examples ".r[0-9]*$" also finds records that end in 'r' since the * quantifier means 0 or more.

Solution 2:

My suggestion for you is to do that with grep - an utility for UNIX-like systems that has been ported to Windows and can match lines using regular expressions.

grep is included with MinGW's MSYS package, the installer can be found here. (install only MSYS)

Then you'll have to add MSYS tools to your PATH variable, dafeult directory for MSYS is C:\MinGW\msys\1.0\bin

Finally you can do your serach with this command:

ls -a | grep ^.+\..+\.r[0-9]+$

... which means: "get output from ls -a (file listing including hidden files) and pass it to grep, match lines that look like ..r[0-9]* (with at least one character symbolized by each asterisk)".