批处理文件定期EX pression找到在名称中的一个数字文件 [英] Batch file regular expression to find files with a digit in the name
问题描述
我想使用一个常规的前pression找到与在名称中位数或某一范围的数字文件的批处理文件的一个例子。
I want an example of a batch file that uses a regular expression to find files with a digit in the name or a certain range of numbers.
有没有办法做到这一点?一个简单的例子?
Is there a way to do this? A simple example?
推荐答案
一些这方面的信贷去Y.A.P.的答案。
Some of this credit goes to Y.A.P.'s answer.
以下code将让你的每个文件与文件名至少有一位数的目录:
The following code will get you 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
的 FINDSTR
行包含了正则表达式前pression。正则表达式的命令行版本是有限的。什么确切的范围,你以后和什么样的格式是文件名吗?
The FindStr
line contains the regex expression. The Command Line version of regex is limited. What exact range are you after and what format are the file names in?
如果,例如,你知道所有的文件在其中有3位数字,您可以将其从000与前pression [0-2] [0限制到所有项目299 -9] [0-9]
。
If, for example, you knew all files had 3 digit numbers in them, you could limit it to all items from 000 to 299 with the expression [0-2][0-9][0-9]
.
这篇关于批处理文件定期EX pression找到在名称中的一个数字文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!