gpt4 book ai didi

regex - Windows 脚本 : list files not matching a pattern

转载 作者:可可西里 更新时间:2023-11-01 11:20:16 24 4
gpt4 key购买 nike

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

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

我的错误在哪里?

非常感谢。

最佳答案

查看 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

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

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

关于regex - Windows 脚本 : list files not matching a pattern,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14440692/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com