批处理文件正则表达式查找名称中包含数字的文件
我想要一个批处理文件的示例,该文件使用正则表达式来查找名称中包含数字或特定数字范围的文件。
有办法做到这一点吗?一个简单的例子?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在一定程度上要归功于 YAP 的回答。
以下代码将获取目录中文件名中至少包含一位数字的每个文件:
FindStr
行包含正则表达式。正则表达式的命令行版本是有限的。您想要的确切范围是什么以及文件名的格式是什么?例如,如果您知道所有文件中都包含 3 位数字,则可以使用表达式
[0-2][0-9][0-9].
Some of this credit goes to Y.A.P.'s answer.
The following code will get you every file in the directory with at least one digit in the file name:
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?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]
.我假设您在这里了解命令提示符/MS-Dos 批处理文件?
如果您很遗憾,答案是否定的,普通旧批处理文件支持的唯一通配符是:
和
? = 匹配 1
所以:
会匹配:
但是还有一个替代方案...
如果您使用现代 Windows 版本,那么您很可能会安装 power-shell,单击
“开始”->“运行”,然后输入 power-shell 并按回车键,如果您打开了看起来像命令提示符窗口的内容,那么您已经安装了它,如果没有,请在 MS 站点上查找下载。
一旦你掌握了这个,如果你想直接深入,你可以在 Reg-ex 上找到你需要的一切就是 PS:
http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-13-text-and-regular-expressions.aspx
但是,我建议首先花一个小时左右的时间学习基础知识。
I'm assuming your on about Command Prompt / MS-Dos batch files here?
If you are then sadly the answer is NO, the ONLY wildcards that plain old batch files support are:
and
? = Match 1
so:
would match:
There is however an alternative...
If your using a modern windows version, then chances are you'll have power-shell installed, click on
start->run then type in power-shell and press return, if you get what looks like a command prompt window open then you have it installed, If not then look on the MS site for a download.
Once you have this, if you want to dive straight in, you can find all you need on Reg-ex is PS here:
http://powershell.com/cs/blogs/ebook/archive/2009/03/30/chapter-13-text-and-regular-expressions.aspx
I would however, recommend spending an hour or so learning the basics first.
findstr 中有。
查看这个
There is in findstr.
Check out THIS