Applying intelligence to 7zip in powershell

This topic contains 2 replies, has 2 voices, and was last updated by  Gavin Williams 2 years, 10 months ago.

  • Author
  • #28817

    Gavin Williams

    Hi All,
    I have a module where I can take in zip files and then I unzip them to a specific directory. However, sometimes the zip files themselves have double-nested folders. e.g. a zip file
    "".. will contain a folder "book1" and then book1.txt. I want to keep the first level such that will create
    but not

    However there aren't always 2 levels... so I want to examine the zip file, check to count how many levels there are, and either extract, or else go *into* the zip file and then extract the subfolder.

    Any ideas ? Many thanks

    		foreach ($i in $files)
    			write-output "$("Setting Location to Directory : ")$($i.DirectoryName)"
                set-location $i.Directoryname
    			Write-Output "$("Expanding ")$($$(" to ")$($workdir)$("\")$($ComicsDir)$("\")$($i.basename)"
    			$extractor = New-Object sevenzip.SevenZipExtractor($i.fullname)                                                                                                                                                                                                    
    			Remove-Item $
    			#$testempty = dir 
    			#if (!$testempty)
    			#	cd ..
    			#	Remove-Item $i.directoryname
    			#	$testempty = $null
  • #28843

    Richard Siddaway

    May be easier to extract the zipped data to a temporary location and then examine

  • #28877

    Gavin Williams

    Interesting idea.. yes that could take me towards the answer.

    Now same question would apply... when I expand them.. how can I do a run across to say... "if there is one subdirectory in the temp folder then move it to the final folder... if there are 2 or more lower subdirectories, then move to the bottom one and move *that* to the final folder"?

You must be logged in to reply to this topic.