49 lines
1.5 KiB
PowerShell
49 lines
1.5 KiB
PowerShell
param(
|
|
[string]$SourceDir,
|
|
[string]$OutputDir,
|
|
[string]$Prefix = "ARC_x64_part",
|
|
[long]$MaxSize = 48000000
|
|
)
|
|
|
|
$SourceDir = $SourceDir.Trim('"', "'", ' ')
|
|
$OutputDir = $OutputDir.Trim('"', "'", ' ')
|
|
|
|
$part = 1
|
|
$currentSize = 0
|
|
$currentFiles = @()
|
|
$allItems = Get-ChildItem -Path $SourceDir -Recurse -File | Sort-Object Length
|
|
|
|
function Flush-Part {
|
|
param($files, $partNum, $size)
|
|
$zipName = Join-Path $OutputDir "$Prefix$partNum.zip"
|
|
Write-Host "Creating part $partNum ($([math]::Round($size/1MB,1)) MB, $($files.Count) files)"
|
|
$tempDir = Join-Path $env:TEMP "arc_split_$partNum"
|
|
if (Test-Path $tempDir) { Remove-Item $tempDir -Recurse -Force }
|
|
foreach ($cf in $files) {
|
|
$dest = Join-Path $tempDir $cf.Rel
|
|
$destDir = Split-Path $dest -Parent
|
|
if (!(Test-Path $destDir)) { New-Item -ItemType Directory -Path $destDir -Force | Out-Null }
|
|
Copy-Item $cf.Full $dest
|
|
}
|
|
Compress-Archive -Path (Join-Path $tempDir '*') -DestinationPath $zipName -Force
|
|
Remove-Item $tempDir -Recurse -Force
|
|
}
|
|
|
|
foreach ($f in $allItems) {
|
|
$rel = $f.FullName.Substring($SourceDir.TrimEnd('\').Length)
|
|
if ($currentSize + $f.Length -gt $MaxSize -and $currentFiles.Count -gt 0) {
|
|
Flush-Part $currentFiles $part $currentSize
|
|
$part++
|
|
$currentSize = 0
|
|
$currentFiles = @()
|
|
}
|
|
$currentFiles += @{ Full = $f.FullName; Rel = $rel }
|
|
$currentSize += $f.Length
|
|
}
|
|
|
|
if ($currentFiles.Count -gt 0) {
|
|
Flush-Part $currentFiles $part $currentSize
|
|
}
|
|
|
|
Write-Host "Done: $part part(s) created."
|