Batch file regular expression to search for files with a number in the name

I need an example batch file that uses a regular expression to search for files with a digit in a name or in a specific range of numbers.

Is there any way to do this? A simple example?

+6
source share
3 answers

Part of this loan belongs to YAP Response.

In the following code, you will receive every file in the directory with at least one digit in the file name:

@Echo Off CD C:\Folder\To\Process Dir /B>Dir.temp FindStr /R "[0-9]" "Dir.temp">FindStr.temp Del Dir.temp For /F "tokens=*" %%a In (FindStr.temp) Do Call :WorkIt "%%a" Del FindStr.temp Exit /B :WorkIt :: Insert code here. Use %1 to get the file name with quotes. For example: Echo Processing %1... Exit /B 

The string FindStr contains a regular expression. The regex command line version is limited. What specific range are you using and what format are the file names?

If, for example, you knew that all files have a 3-digit number in them, you can limit it to all elements from 000 to 299 using the expression [0-2][0-9][0-9] .

+10
source

I assume you are participating in / MS -Dos command line batch files here?

If you later, unfortunately, answer NO, the only wildcards that support plain old batch files are:

  * = match all 

and? = Match 1

So:

  mytune*.mp? 

will match:

  mytune01.mp3, mytune01.mpg, mytune-the-best.mpe 

However, there is an alternative ...

If you are using a modern version of Windows, then most likely you will have Power-shell installed, click

start-> run, then type power-shell and press return, if you get what looks like a command prompt window open, then you installed it. If then, look at the MS website for download.

Once you do this, if you want to dive right in, you can find everything you need in Reg-ex, here's the PS:

http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-13-text-and-regular-expressions.aspx

I would suggest spending an hour or so learning the basics.

+2
source

In findstr. Check it out

+1
source

Source: https://habr.com/ru/post/897077/


All Articles