在Windows 7命令提示符中,我想列出名称不以abc开头的文件夹的所有文件。 我努力了:
forfiles /P C:\myFolder\ /M ^[abc]* /S /C "CMD /C echo @file"我的错误在哪里?
非常感谢。
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.
最满意答案
看forfiles /? :
/M searchmask Searches files according to a searchmask. The default searchmask is '*' .
强烈建议forfiles不支持正则表达式,只是正常的Cmd / Windows通配符。
在Windows 7上,这可以在PowerShell中轻松实现:
dir c:\myFolder | ?{ -not($_.Name -match '^abc') } | select Name(它执行一个敏感的正则表达式匹配的情况,在Windows文件名的情况下无关紧要。)
NB。 假设您希望文件不启动ABC ,这不是您的(尝试过的)正则表达式所说的(任何文件名都不a , b或c )。
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).
更多推荐
发布评论