-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7zfolder.ps1
41 lines (39 loc) · 1.13 KB
/
7zfolder.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
param(
[int32]$jobs,
[string]$path = $PWD,
[switch]$h
)
if ($jobs -eq 0) {
if ($IsWindows) {
$jobs = (Get-CimInstance -ClassName 'Win32_ComputerSystem').NumberOfLogicalProcessors
} elseif ($IsMacOS) {
$jobs = sysctl -n hw.ncpu
} else {
$jobs = grep.exe -c ^processor /proc/cpuinfo
}
}
if ($h) {
Write-Output "Tars folders in `$path"
Write-Output "Must have 7z in env:path"
Write-Output "Slightly tested on *nix"
Write-Output " -jobs [$jobs] for the ammount of concurrent converts"
Write-Output " -path [$path] where 7z will look from and output to"
exit
}
if (-Not (Test-Path -Path $path)) {
Exit
}
Get-ChildItem -Directory $path | ForEach-Object {
$Check = $false
while ($Check -eq $false) {
if ((Get-Job -State 'Running').Count -lt $jobs) {
Start-Job -ArgumentList $_, $path -ScriptBlock {
param($folder, $path)
$folder = Get-Item $folder
7z.exe a $path/$($folder.basename).tar $($folder.FullName + '/*')
}
$Check = $true
}
}
Remove-Job -State Completed
}