我想存档与正则表达式模式(/[0-9]{4}/
)相匹配的目录。7z支持吗?
找不到匹配的目录:
PS> 7z a -t7z C:\Users\<user>\Desktop\Archive.7z '/[0-9]{4}/'
7-Zip不使用系统通配符解析器。7-Zip不遵循的古老规则。表示任何文件。7-Zip零食。与任何具有扩展名的文件的名称匹配。要处理所有文件,必须使用*通配符。
# Get only objects with names consisting of 4 characters
[array]$Folders = Get-ChildItem -Path '.\' -Filter '????' |
# Filter folders matching regex
Where-Object {$_.PsIsContainer -and $_.Name -match '[0-9]{4}'} |
# Get full paths. Not really needed,
# PS is smart enough to expand them, but this way it's more clear
Select-Object -ExpandProperty Fullname
# Compress matching folders with 7Zip
& '7z.exe' (@('a', '-t7z', 'C:\Users\<user>\Desktop\Archive.7z') + $Folders)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句