20

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?

1
  • 3
    Welcome to SU! On stackexchange sites, when an answer has helped you, the way to thanking people is to upvote their answer and to accept it (by clicking on the checkmark to the left of an answer) if it solved your problem. I'm only saying because you seem to have accepted none of the answers you have received for your questions.
    – terdon
    Mar 24, 2013 at 14:33

4 Answers 4

21

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]*[0-9]$

Updates

Be careful, the * in one of the other examples ( ".r[0-9]*$") finds all or none of the number range [0-9], so it also finds records that end in 'r' only which is not expected.

My original answer used a RegEx + after the number, but as @ScottChu pointed out, that's not an option in findstr.

This answer was also updated with a variant of the comment by @ndreisg which also works, however, the $ is still needed at the end to ensure the match closes with the number and doesn't find it in the middle of the string.

WSL

Also, in addition to installing GNU grep, you can now install the Windows Subsystem for Linux.

3
  • Hi cpattersonv1 - thanks for responding dir * /s /b | findstr \.r[0-9]*$ works
    – chz
    Mar 29, 2013 at 20:27
  • 1
    findstr seems doesn't recognize the 1 or many symbol '+'
    – Scott Chu
    Mar 6, 2018 at 8:54
  • findstr doesn't recognize the + quantifier. I used [0-9][0-9]* instead
    – ndreisg
    Jan 14, 2021 at 16:26
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)".

3
  • hi gronostaj thanks for the response; I tried $ ls -R | grep -H ^.*[0-9]$ (standard input):res.jar.r469621 (standard input):res.jar.r464460 (standard input):test.jar.r46521 (standard input):test.jar.r46970
    – chz
    Mar 24, 2013 at 20:23
  • Hi I still cant get the full path name of the filename; how do I do that ? eg c:\pager\test.jar.r46521 as opposed to (standard input):test.jar.r46521
    – chz
    Mar 24, 2013 at 20:25
  • ls | grep is the same as dir | findstr in Windows. Mar 28, 2013 at 21:32
1

Please try by navigating to c:\windows\system32 where the findstr is located and then execute the suggested commands.

0

You can try this:

dir /a| findstr .r[0-9]*$

For help, type findstr /?.

7
  • Hi mfm4aa thanks for responding - cant seem to work; I've tried all combinations and none gives ant listed answer: Eg inline C:\Temp>findstr /S /B [0-9] . C:\Temp>findstr /S /B r[0-9]$ . C:\Temp>findstr /S /B $.*r[0-9]$ C:\Temp>findstr /S /B $.*r*$ C:\Temp>findstr /S /B $.*r..*$ C:\Temp>findstr /S /B $.*r\..*$ C:\Temp>findstr /S /B /R $.*r\..*$ C:\Temp>findstr /S /B /R "$.*\..r[0-9]*$ C:\Temp>findstr /S /B /R "$.*\..r[0-9]*$" C:\Temp>findstr /S /B /R "$.*\..r[0-9]*$" . C:\Temp>findstr /S /B /R "$.*\..r[0-9]$" . C:\Temp>findstr /S /B /R "$.*[0-9]*" . C:\Temp>findstr /S /B /R "$*[0-9]*" .
    – chz
    Mar 24, 2013 at 19:27
  • Please try: C:\Temp>dir /aa| findstr .r[0-9]*$
    – Endoro
    Mar 24, 2013 at 19:32
  • Hi mfm thanks for writing - i still cant find C:\Temp>dir /aa | findstr .r[0-9]*$ File Not Found
    – chz
    Mar 24, 2013 at 20:29
  • :) simply type dir /aa| findstr .r[0-9]*$. That does working here...
    – Endoro
    Mar 24, 2013 at 20:36
  • Hi Endoro thanks for responding. It didn't work - it says File Not Found
    – chz
    Mar 29, 2013 at 20:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .