7z archive inclui diretórios correspondentes a regex

2

Eu gostaria de arquivar diretórios que correspondam a um padrão de expressão regular ( /[0-9]{4}/ ). O 7z apóia isso?

Isso não encontra diretórios correspondentes:

PS> 7z a -t7z C:\Users\<user>\Desktop\Archive.7z '/[0-9]{4}/'
    
por Craig 23.10.2015 / 00:23

1 resposta

3
  1. 7Zip não suporta regex, apenas curingas. Citação do pacote manual:

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.

  1. Se você estiver usando o PowerShell, provavelmente poderá fazê-lo funcionar dessa maneira:
# 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)
    
por 23.10.2015 / 02:08