-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBulk-Folder-Zip.ps1
More file actions
24 lines (19 loc) · 943 Bytes
/
Copy pathBulk-Folder-Zip.ps1
File metadata and controls
24 lines (19 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Prompt the user for source and destination folders
$SourceFolder = Read-Host "Enter the source folder"
$DestinationFolder = Read-Host "Enter the destination folder for zipped files"
# Check if the source folder exists
if (-Not (Test-Path $SourceFolder -PathType Container)) {
Throw "The source directory $SourceFolder does not exist, please specify an existing directory"
}
# Check if the destination folder exists, if not, create it
if (-Not (Test-Path $DestinationFolder -PathType Container)) {
New-Item -ItemType Directory -Path $DestinationFolder | Out-Null
}
$date = Get-Date -format "yyyy-MM-dd"
$folders = Get-ChildItem -Path $SourceFolder -Directory
foreach ($folder in $folders) {
$dirPath = $folder.FullName
$destinationPath = Join-Path $DestinationFolder "$($folder.Name)_$date.zip"
Compress-Archive -Path $dirPath -CompressionLevel 'Fastest' -DestinationPath $destinationPath
}
Write-Host "Compressed!!"