2
1
I would like to archive directories that match a regular-expression pattern (/[0-9]{4}/
). Does 7z support this?
This doesn't find matching directories:
PS> 7z a -t7z C:\Users\<user>\Desktop\Archive.7z '/[0-9]{4}/'
2
1
I would like to archive directories that match a regular-expression pattern (/[0-9]{4}/
). Does 7z support this?
This doesn't find matching directories:
PS> 7z a -t7z C:\Users\<user>\Desktop\Archive.7z '/[0-9]{4}/'
3
7-Zip doesn't uses the system wildcard parser. 7-Zip doesn't follow the archaic rule by which . means any file. 7-Zip treats . as matching the name of any file that has an extension. To process all files, you must use a * wildcard.
# 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)
1I'm going to mark your answer as accepted--got me heading in the right direction. Actual syntax:
7z a -t7z C:\Users\<user>\Desktop\Archive.7z ( Get-ChildItem . | Where-Object { $_.Name -Match "^[0-9]{4}" })
– Craig – 2015-10-23T01:24:52.360