Monitor folder for new incoming folders/files, wait for them to download, then move to archive folder and zip

Viewed 29

This is the behaviour I'm trying to get. I have files within folders that download into a folder. I need powershell to monitor this folder, wait for all the files within the subfolders to finish downloading, and then move them to a parallel local archive folder and zip them up. It's important that the names of the folders don't change so if they're called 01004354 they just become 01004354.zip

I've seen some solutions but these incoming folders can be really big and it can take an hour or so for them to download - and I'm worried the archives then would fail or be incomplete.

$source = "C:\scripts"
$archive = "C:\Archive"
$Name = "Script.zip"
$destination = "\\dc1\share\scripts"
$ArchiveFile = Join-Path -Path $archive -ChildPath $Name
MD $archive -EA 0 | Out-Null
If(Test-path $ArchiveFile) {Remove-item $ArchiveFile}
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::CreateFromDirectory($Source, $ArchiveFile)
Copy-Item -Path $ArchiveFile -Destination $destination -Force

I think this would work but I need to make sure the names are preserved.

0 Answers
Related