Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to zip multiple files into zip with Copy-ToZip from PowerShellPack?

Tags:

powershell

zip

I installed the PowerShellPack to zip multiple files into zip. It works with small files like .txt, but not with large files. Only one file is in the zip and I get the error File not found or no read permission.

Import-Module PowerShellPack
Copy-ToZip -File "D:\Temp\Test.adi" -zipfile "D:\Temp\Files.zip"
Copy-ToZip -File "D:\Temp\Test2.adt" -zipfile "D:\Temp\Files.zip"

I tried to use the Wait-Job command, but this also only works with small files. With large files a zip-file is created, but it is empty.

Import-Module PowerShellPack
$job = Start-Job {Copy-ToZip -File "D:\Temp\Test.adi" -zipfile "D:\Temp\Files.zip"}
Wait-Job $job
Receive-Job $job
$job = Start-Job {Copy-ToZip -File "D:\Temp\Test2.adt" -zipfile "D:\Temp\Files.zip"}
Wait-Job $job
Receive-Job $job
like image 984
Daniacc Avatar asked Nov 29 '25 12:11

Daniacc


1 Answers

I recommend using the Write-Zip cmdlet included in the PowerShell Community Extensions instead. It doesn't have the file access problems that Copy-ToZip has.

Example usage:

Get-ChildItem D:\Temp\*.ad* | Write-Zip -OutputPath D:\Temp\Files.zip

If -OutputPath is not specified, a zip file will be created for each input file rather than a single zip file.

It also has a -Level switch to specify compression level.

like image 139
n4cer Avatar answered Dec 01 '25 07:12

n4cer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!