Windows 脚本:列出与模式不匹配的文件 [英] Windows scripting: list files not matching a pattern
问题描述
在 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
开头,这不是您(尝试的)正则表达式所说的(任何以不是 a
、b
或 c
).
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屋!