ExtractToDirectory with no folder

Hi

I've got a zip file with this structure: test.zip -> Mark -> Today-> *.* ( every files)

When I extract it , as a result I get this : test (folder) -> Mark (folder) -> Today ->. ( every files)

How Can I get this structure : Today (folder) ->. (every files)

I mean , I trying to avoid the first two folders creation.

The best thing to be would be extract only the files without folders

EDIT :

I had to edit my question

A pragmatic way would be to extract the archive as it is and afterwards move the folder “Mark” one directory up and delete the now empty folder “test”. You might show the code you’re using to extract your archive.

[quote quote=196139]A pragmatic way would be to extract the archive as it is and afterwards move the folder “Mark” one directory up and delete the now empty folder “test”. You might show the code you’re using to extract your archive.

[/quote]

Thanks Olaf this is my old code

{
param([string]$zipfile, [string]$outpath)
#[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
Expand-Archive -Path $zipfile -DestinationPath $outpath
}
 
I've received an answer from StackOverflow , I want share with you
function Unzip2 {
param([string]$zipfile, [string]$out)
$Archive = [System.IO.Compression.ZipFile]::OpenRead($zipfile)
Foreach ($entry in $Archive.Entries.Where( { $_.Name.length -gt 0 })) {
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($entry, "$out\$($entry.Name)")
}
$Archive.Dispose()
}
I discovered the pipeline concept and the '$_ ' . I'm going to study :D
Too bad it hasn't a graphic text like expand-archive !
 

It’s been me asking you there why you’re not using Expand-Archive. :wink:

What do you mean with “hasn’t a graphic text”?

Hello Olaf

I had not been doing Expand- Archive because I didn’t know it : I started writing my first script a week ago :expressionless:

Can I only download every files throught Expand-Archive?

When I talk about “graphic text” I want to say that ‘ExtractToFile’ doesn’t use progress bar or colored foreground/backcolor

as the Expand-Archive does

Thank

Unfortunately not. Expand-Archive will expand the archive just as it is. You could unzip the files to a temporary folder and move them afterwards to a final target location if that’s needed - maybe for an automation task or so. :wink:

Ah … I understand. And unfortunately the answer to this question is “No” as well. If that’s crucial for you wou would need to create that functionality by yourself. But do you really need color to unzip some files? The files will be the same later - no mater what color the unzipper showed. :wink:

+1

Thank