Created
July 29, 2023 14:26
-
-
Save isurfer21/12ea6453913c7b6f62914302ff9370b9 to your computer and use it in GitHub Desktop.
A PowerShell based CLI app to zip each folder in the source directory and paste them to the target directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$help = $false | |
if ($args -contains "-h" -or $args -contains "--help") { | |
$help = $true | |
} | |
if ($help) { | |
write-host "Usage" | |
write-host " zipnsync [options] <source> <target>" | |
write-host "" | |
write-host "Arguments" | |
write-host " source set source directory path to copy folders from" | |
write-host " target set target directory path to paste zipped folder in" | |
write-host "" | |
write-host "Options" | |
write-host " -h --help show help menu" | |
write-host "" | |
} else { | |
# Define the source and target directories | |
$source = $args[0] | |
$target = $args[1] | |
if (-not $source) { | |
write-host "Error: Missing source directory path" | |
} elseif ($source -and (-not (Test-Path "$source"))) { | |
write-host "Error: Source directory path not found" | |
} elseif (-not $target) { | |
write-host "Error: Missing target directory path" | |
} elseif ($target -and (-not (Test-Path "$target"))) { | |
write-host "Error: Target directory path not found" | |
} else { | |
# Get all the folders in the source directory | |
$folders = Get-ChildItem -Path $source -Directory | |
# Loop through each folder | |
foreach ($folder in $folders) { | |
# Get the folder name | |
$name = $folder.Name | |
# Compress the folder using 7-Zip command line | |
& 7z a -t7z "$name.7z" $folder.FullName | |
# Move the compressed file to the target directory | |
Move-Item -Path "$name.7z" -Destination $target | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This programme will help you quickly obtain a concise segregated backup of your subdirectories.