Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

22
LINES

< > BotCompany Repo | #1001335 // zip2dir

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (3211L/18K).

static void zip2dir(File inZip, File/S outDir) {
  zip2dir(inZip, outDir, "");
}

static void zip2dir(File inZip, File/S outDir, S prefix) ctex {
  if (prefix.length() != 0 && !prefix.endsWith("/")) prefix += "/";
  
  temp ZipFile zipFile = new ZipFile(inZip);
  Enumeration entries = zipFile.entries();
  while (entries.hasMoreElements()) {
    ZipEntry entry = (ZipEntry) entries.nextElement(); 
    
    if (entry.isDirectory()) continue; // We care about files only, really. Directories are made on the fly anyway.
    
    if (!entry.getName().startsWith(prefix)) continue;
    
    File outFile = new File(outDir, entry.getName());
    print("Unzipping " + entry.getName() + " to " + outFile.getAbsolutePath());
    
    stream2file(zipFile.getInputStream(entry), outFile);
  }
}

Author comment

Began life as a copy of #1001173

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ekrmjmnbrukm, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001335
Snippet name: zip2dir
Eternal ID of this version: #1001335/4
Text MD5: 62d4b7420a26c4691a6bd719a35c6001
Transpilation MD5: b3bb3bc38346875cc1b14fd808def64f
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-08-29 23:50:40
Source code size: 809 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 800 / 1053
Version history: 3 change(s)
Referenced in: [show references]