用于自动增加ZIP压缩的代码?

问题描述:

我想ZIP文件夹中的800张图片,每个ZIP文件只包含10个或更少的图片,所以我应该结束了80个ZIP文件。如果有人知道BAT文件的代码来做到这一点,我会非常感激。我也不想在压缩后删除文件。用于自动增加ZIP压缩的代码?

我知道我可能会使用7-Zip,但我似乎无法在任何地方找到答案。谢谢!

+0

7zip和可能最压缩的工具,只能按文件大小不能分割https://sevenzip.osdn.jp/chm/cmdline/switches/volume.htm,你需要每一个zip文件来提取单个文件。你应该指定目的或期待结果 – Deptor

请尝试以下PowerShell

# Setup variables (Change) 
$ZipFolder = "T:\YourFolder\WithFiles\ToZip" 
$7Zip = "C:\Program Files\7-Zip\7z.exe" 
$NewZipsFolder = "T:\FolderToPut\AllOfThe\ZipsIn" 

# Script Variables 
$pendingFiles = @() 
$fileNumber = 1 

# Get a list of all the files to be zipped 
Get-ChildItem $ZipFolder | sort $_.FullName | ForEach-Object { $pendingFiles += $_.FullName } 

# While there are files still to zip 
While($pendingFiles){ 

    # Select first 10 files to zip and zip them 
    $ToZip = $pendingFiles | Select -First 10 
    & $7Zip "a" "$NewZipsFolder\File-$fileNumber.7z" $ToZip 

    # Remove first 10 zipped files from pending files array 
    $pendingFiles = $pendingFiles | Where-Object { $ToZip -notcontains $_ } 
    $fileNumber++ 
} 

这将创建一个需要被拉链中的所有文件的列表。然后使用7z.exe(7-zip)将它们分批压缩成10个文件。

注意:对于变量$ZipFolder & $NewZipsFolder不要把尾部的反斜杠的文件夹路径(\)。

+0

这工作!非常感谢!你刚刚救了我几个小时的工作!我确实将.7z换成了我所需要的.zip,但它做了它应该做的事! –

你可以使用的东西沿着

$fileList = Get-Item -Path "C:\MyPhotosDir\*" 

行文件的列表存储在PowerShell中后,再设置7zip的别名

set-alias sz "$env:ProgramFiles\7-Zip\7z.exe" 

然后创建沿线的一个计数器循环

$i = 1 
foreach $file in $fileList 
    #Build foder name name 
    $folderDir = "C:\MyPhotoArchive$($i - ($i % 10) + 1).7z" 
    sz a -t7z $folderDir $file.filename 
end for 

我一直在VB写作一段时间,所以道歉,如果Powershell语法有点偏离。本质上应该添加10个文件到“C:\ MyPhotoArchive1”,10个文件添加到“C:\ MyPhotoArchive2”。我很长一段时间没有使用7zip将文件添加到存档中,但我认为该调用仅使用a,并应将文件添加到存档,并在需要时创建一个。