使用Powershell和7zip通过首字母将文件放入单独的.7z中

问题描述 投票:0回答:2

我有一个脚本,该脚本根据起始字母将文件放入文件夹中(例如,以'A'开头的文件将转到名为“ A”的文件夹,以'B'开头的文件夹,名为“ B”的文件夹,依此类推。)代码如下:

97..122 | foreach {
    $letter=[char]$_
    New-Item -Path .\ -Name $letter -ItemType "directory"  
    move-item .\$letter`?* $letter
    $list +=  $letter
}

$rest=get-childitem -path .\ -exclude $list 
New-Item -Path .\ -Name "rest" -ItemType "directory"

foreach ($f in $rest) {
    move-item  $f.fullname "rest"
}

我想知道是否有办法做到,但是要用7zip将它们压缩为.7z文件(最好是在“ Ultra”上压缩),而不是文件夹。

powershell sorting 7zip explorer
2个回答
0
投票

您将使用Start-Process使用-ArgumentList指定命令来启动7z。

https://superuser.com/questions/940878/how-to-pass-multiple-files-to-zip-in-a-single-command-using-7-zip

'a'命令将文件添加到存档。


0
投票

这样的事情?

'a'..'z' | ForEach-Object {
    7z.exe a -mx9 -o "$OutputFolder" "$_.7z" ".\$_*.*"
}

您需要查阅7-Zip文档以了解7z.exe命令语法。

© www.soinside.com 2019 - 2024. All rights reserved.