Windows 脚本:列出与模式不匹配的文件 [英] Windows scripting: list files not matching a pattern

查看:83
本文介绍了Windows 脚本:列出与模式不匹配的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Windows 7 命令提示符下,我想列出名称不以 abc 开头的文件夹的所有文件.我试过了:

forfiles/P C:\myFolder\/M ^[abc]*/S/C "CMD/C echo @file"

我的错误在哪里?

非常感谢.

解决方案

forfiles/?:

<块引用>

/M searchmask 根据搜索掩码搜索文件.默认搜索掩码是 '*' .

强烈建议 forfiles 不支持正则表达式,只支持普通的 Cmd/Windows 通配符.

在 Windows 7 上,这可以在 PowerShell 中轻松实现:

dir c:\myFolder |?{ -not($_.Name -match '^abc') } |选择名称

(执行区分大小写的正则表达式匹配,这在 Windows 文件名的情况下无关紧要.)

注意.假设您希望文件不以 ABC 开头,这不是您(尝试的)正则表达式所说的(任何以不是 abc).

In Windows 7 command prompt, I´d like to list all files of a folder which name does not start with abc. I have tried:

forfiles /P C:\myFolder\ /M ^[abc]* /S /C "CMD /C echo @file"

Where is my error?

Many thanks.

解决方案

Looking at forfiles /?:

/M    searchmask    Searches files according to a searchmask.
                    The default searchmask is '*' .

which strongly suggests forfiles doesn't support regular expressions, just normal Cmd/Windows wildcards.

On Windows 7 this can easily be achieved in PowerShell:

dir c:\myFolder | ?{ -not($_.Name -match '^abc') } | select Name

(That performs a case-insensitive regular expression match, which doesn't matter in the case of Windows filenames.)

NB. Assuming you want files not starting ABC, which isn't what your (attempted) regular expression says (any filename starting something that isn't a, b or c).

这篇关于Windows 脚本:列出与模式不匹配的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆