customer relationships

Zip Files to New Folder

If you need to zip up all the files in directory and send them to a new folder here is a quick PowerShell script that will work. This script will place a date on the filename when zipped to ensure you do not overwrite any data.

The Start-Sleep command is used to make sure the script does not finish prematurely before all the files are zipped up. The -s 1200 can be adjusted depending on the size of the files being zipped.

$DestZip='E:\Logs\Weekly_Backups\'
$Dest = "E:\Logs\All_Logs\"
$ZipTimestamp = Get-Date -format yyyy-MM-dd-HH-mm-ss;
$ZipFileName  = $DestZip + "Backup_" + $ZipTimestamp + ".zip"
set-content $ZipFileName ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18))
# Wait for the zip file to be created.
while (!(Test-Path -PathType leaf -Path $ZipFileName))
{  
    Start-Sleep -Milliseconds 20
}
$ZipFile = (new-object -com shell.application).NameSpace($ZipFileName)
 
Write-Output (">> Waiting Compression : " + $ZipFileName)      
$ZipFile.MoveHere($Dest)
Start-Sleep -s 1200

Got a project that needs expert IT support?

From Linux and Microsoft Server to VMware, networking, and more, our team at CR Tech is here to help.

Get personalized support today and ensure your systems are running at peak performance or make sure that your project turns out to be a successful one!

CONTACT US NOW
one click social media designs