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

37
LINES

< > BotCompany Repo | #1001174 // dir2zip (no subdirectories - use dir2zip_recurse for that)

JavaX fragment (include)

// TODO: subdirectories
// Now sorts file list first (to ensure reproducable MD5 of zip)
static int dir2zip(File inDir, ZipOutputStream outZip, String outPrefix) ctex {
  new L<File> files;
  for (File f : inDir.listFiles())
    if (f.isFile())
      files.add(f);

  sortFilesByName(files);
  for (File f : files) {
    System.out.println("Copying " + f.getName());
    outZip.putNextEntry(new ZipEntry(outPrefix + f.getName()));
    InputStream fin = new FileInputStream(f);
    copyStream(fin, outZip);
    fin.close();
  }
  return files.size();
}

static int dir2zip(File inDir, ZipOutputStream outZip) {
  return dir2zip(inDir, outZip, "");
}

static int dir2zip(String inDir, ZipOutputStream outZip) {
  return dir2zip(new File(inDir), outZip, "");
}

static int dir2zip(File inDir, File zip, S outPrefix default "") ctex {
  mkdirsForFile(zip);
  FileOutputStream fout = new FileOutputStream(zip);
  ZipOutputStream outZip = new ZipOutputStream(fout);
  try {
    ret dir2zip(inDir, outZip, outPrefix);
  } finally {
    outZip.close();
  }
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1001174
Snippet name: dir2zip (no subdirectories - use dir2zip_recurse for that)
Eternal ID of this version: #1001174/2
Text MD5: 0f540d087f2d5fb3eb9c8f40a6aeea3d
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-04-28 14:58:39
Source code size: 1086 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 787 / 996
Version history: 1 change(s)
Referenced in: #1002204 - dir2zip_recurse
#1002427 - Accellerating 629 (SPIKE)
#1006654 - Standard functions list 2 (LIVE, continuation of #761)
#3000382 - Answer for ferdie (>> t = 1, f = 0)