简体   繁体   中英

Powershell - Moving Files/Folders in a ZIP up one directory?

I have a ZIP archive, who's directory structure looks like this.

Root. ZIP

Level 1. Folder

Level 2. Files/Folders

What I'm currently doing is extracting the ZIP, moving all of the files up to the correct directory, deleting the now empty folder and then finally zipping up the folder again.

My question is, is there a way to do this without needing to extract the initial archive at all?

You can load Zip files into memory without extracting them on the disk.

$ZipFile = "C:\zipfolder\test.zip"

Add-Type -AssemblyName System.IO
Add-Type -AssemblyName System.IO.Compression

$FileStream = [System.IO.File]::OpenRead($ZipFile)
$ArchiveInMemory = [System.IO.Compression.ZipArchive]::new($file)

Add-types will load up the classes needed.

OpenRead will load the file into memory.

ZipArchive will interpret the file in memory as a zip archive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM