Forum Discussion
Compress-Archive Not Working?
Thank you LainRobertson
I had read through that article and completely missed the obvious answer:
This: Compress-Archive -Path 'D:\abc\' -DestinationPath 'D:\xyz\abc.zip'
Instead of this: Compress-Archive -Path 'D:\abc\*.*' -DestinationPath 'D:\xyz\abc.zip'
Is working perfectly.
In fact, the folder D:\abc is indeed empty, but there are multiple folders on the next level.
If I may, I have two more questions.
I believe I read somewhere that using this compression method is limited to 2gb file sizes?
Is there a way to remove files from a compressed file leaving everything else in tact?
Thanks again for your quick answer and that excellent article!
Hey, John.
Yes, you certainly can manipulate an archive, however, you have to do so from .NET. Here's a very basic example, which you can easily extend as it's a pretty simple set of classes to work with.
Example
# Add the required .NET library reference.
Add-Type -AssemblyName "System.IO.Compression.FileSystem";
# Open the Zip file.
$Archive = [System.IO.Compression.ZipFile]::Open("<full path to your Zip file>", [System.IO.Compression.ZipArchiveMode]::Update);
# Delete the first entry.
$Archive.Entries[0].Delete();
# Finish up properly by disposing the $Archive object.
$Archive.Dispose();
In a real-world context, you'd most likely enumerate the Entries collection and make smarter decisions based on file size, type, etc.
References
- ZipFile Class (System.IO.Compression) | Microsoft Learn
- ZipArchive Class (System.IO.Compression) | Microsoft Learn
- ZipArchiveEntry Class (System.IO.Compression) | Microsoft Learn
Cheers,
Lain
- johnmschNov 18, 2023Copper Contributor
Thanks again for all you help LainRobertson
Hope you have a wonderful weekend!