1

I am extracting a zip file in Java with Zip4j.

The zip will look something like this:

ZipName.zip
    |
    ->foo/
        |
        ->SomeDirectory/
        ->fooBar.dll

I write

ZipFile zipFile = new ZipFile("ZipName.zip");
zipFile.extractFile("foo/", "destination/");

And after extraction I want my destination to look like this:

desitnation/
    |
    ->SomeDirectory/
    ->fooBar.dll

But instead, it looks like this:

destination/
    |
    ->foo/
        |
        ->SomeDirectory/
        ->fooBar.dll

So I want each FileHeader in foo/ to go directly to destination/ without creating directory foo/ in destination. Is this possible?

EP1997
  • 31
  • 1
  • 4
  • Where's `/bar`? – shmosel Dec 28 '21 at 23:50
  • @shmosel That was a mistake. Fixed now. – EP1997 Dec 28 '21 at 23:52
  • I don't know zip4j, but this behavior is pretty standard for zip libraries. If there are no other files in destination, you could rename `foo` -> `destination` after unzipping. Otherwise you might be able to do it manually by listing the zip and using this to unzip one file at a time to the right place. It's likely that will be painful and fragile. A last resort. Otoh, moving files "up one directory" is cheap on all file systems I know. – Gene Dec 29 '21 at 00:13
  • @Gene Thanks for the info and I'll give up one directory a shot, sounds like it should do what I need. – EP1997 Dec 29 '21 at 01:37

0 Answers0