1

I have a large zip file (101 GB) and I don't have enough disk space to directly copy all the files inside the zip archive. I was wondering if there was a way to extract the contents of the zip file and at the same time delete the files that have already been copied out of the archive. So, at the end of the action, I would have a zip file with nothing inside it and a folder with all the contents of the zip file. I should mention that the zip file has folders inside it with pictures inside those folders. How would I have the photos be copied/deleted one by one? I am open to using Powershell, Command Prompt, C++, and Python.

2 Answers 2

1

Try this using powershell based on modified code from https://stackoverflow.com/questions/20269202/remove-files-from-zip-file-with-powershell. I modified it as per your needs.

[Reflection.Assembly]::LoadWithPartialName("System.IO.Compression")
$zipfile = "Zip file path here"
$OutFolder = "Output folder here"
$stream = New-Object IO.FileStream($zipfile, [IO.FileMode]::Open)
$mode   = [IO.Compression.ZipArchiveMode]::Update
$zip    = New-Object IO.Compression.ZipArchive($stream, $mode)
$zip.Entries | Foreach {
   $ToDel = $_  
  [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_,"$($OutFolder)\$($_.Name)",$true)
$ToDel.Delete()
}
$zip.Dispose()
$stream.Close()
$stream.Dispose()
1
  • This returns a Unable to find type [System.IO.Compression.ZipFileExtensions]. error. I am fairly new to PowerShell so I don't know what's wrong with this code.
    – Fateh A.
    Jul 16, 2020 at 4:11
0

I know this is rather old, but the info in it is incorrect. To get to ZipFileExtensions, you need to have a reference to System.IO.Compression.FileSystem first. This would be a lot easier to do by writing a bit of C# code.

Andy

1
  • Can you give, editing your answer, a sample of such code? Apr 30, 2021 at 19:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .