node-unzipper icon indicating copy to clipboard operation
node-unzipper copied to clipboard

Extracting all of the file from a folder

Open mmajcica opened this issue 6 years ago • 5 comments

I have a root folder in my zip file. I'm looking to extract all of the files in it, however in the destination folder this root folder should not appear.

Example: myFile.zip -> rootFolder - files

if I extract it to c:\temp, I do get c:\temp\rootFolder\files What I am looking for is to end up with c:\temp\files

Is there an elegant way to achieve this with the unzipper?

mmajcica avatar Mar 11 '19 10:03 mmajcica

Not currently with the Extract method as it simply appends the full path of the file to the target directory. You can however do this manually with either unzipper.Parse() and on each entry remove the part of the path you want to ignore and just use the first example in the readme (using fstream.Writer if you want sub-directories automatically created)

Leaving this issue open as this is a good feature request (PRs welcome)

ZJONSSON avatar May 21 '19 01:05 ZJONSSON

You can take a hint from tar which has an option for to strip count leading path elements on extract:

--strip-components count
        (x mode only) Remove the specified number of leading path elements. 
        Pathnames with fewer elements will be silently skipped.  Note that
        the pathname is edited after checking inclusion/exclusion patterns
        but before security checks.

silverwind avatar Jun 03 '19 23:06 silverwind

can i implement this feature or its already done

asapluiz avatar Sep 22 '23 13:09 asapluiz

Was really hoping this would have complete parity with tar so I could make them completely interchangeable in my code depending on filetype. Would a PR for this be considered?

josh-hemphill avatar Mar 26 '24 06:03 josh-hemphill

@josh-hemphill absolutely, as long as backward compatible

ZJONSSON avatar Jun 09 '24 00:06 ZJONSSON