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.

$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)      
Start-Sleep -s 1200
one click social media designs

Leave a Reply

Your email address will not be published. Required fields are marked *