PowerShell Extract from zip file 17 folders deep -


i have zip file automatically created , can't change number of folders within it.

i trying extract contents folder 17 folders deep within zip file. issue name of folders can change.

i started use 7zip extract zip folder , works fine:

$zipexe = join-path ${env:programfiles(x86)} '7-zip\7z.exe' if (-not (test-path $zipexe)) {     $zipexe = join-path ${env:programw6432} '7-zip\7z.exe'     if (-not (test-path $zipexe)) {          '7-zip not exist on system.'     } } set-alias zip "c:\program files\7-zip\7z.exe" zip x $webdeployfolder -o \$webdeploytempfolder  

is there way extract content in folder 17 folders deep within zip file?

you can use 7zip's listing function contents of file. can parse output, looking folder 17 levels , use path extract contents.

below chunk of code that.

$7zip = "${env:programfiles(x86)}\7-zip\7z.exe" $archivefile = "c:\temp\archive.zip" $extractpath = "c:\temp" $archivelevel = 17  # contents list zip file $zipcontents = & $7zip l $archivefile  # filter contents folders, described "d" in attr column $contents = $zipcontents | where-object { $_ -match "\sd(\.|[a-z]){4}\s"}  # line folder level defined in $archivelevel present $folderline = $contents | where-object { ($_ -split "\\").count -eq ($archivelevel) }  # folder path line $folderpath = $folderline -split "\s" | where-object { $_ } | select-object -last 1  # extract folder desired path. includes entire folder tree contents of desired folder level start-process $7zip -argumentlist "x $archivefile","-o$extractpath","$folderpath" -wait  # move contents of desired level top of path move-item (join-path $extractpath $folderpath) -destination $extractpath  # remove remaining empty folder tree remove-item (join-path $extractpath ($folderpath -split "\\" | select-object -first 1)) -recurse 

there couple of caveats in code. couldn't find way extract folder without full path/parensts. cleaned in end. note parent folders not contain other files or folders. also, had use "start-process" @ end or 7zip break variable input.

you have change bit depending on zip file structure, should going.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -