1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
   | // ZipDir ( fm_dirIn ; fm_fileOut )
// 10_12_23_JR WORKING
// v1.0
// adds all of tree from starting directory to zip file
// adapted from Solomon Duskis, http://www.jroller.com
// without diacriticals chars (accents) in path name
 
import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
 
try {
topDir = new File(fm_dirIn) 
zipOut = new ZipOutputStream ( new FileOutputStream(fm_fileOut) ); 
 
topDirLength = topDir.absolutePath.length()
 
topDir.eachFileRecurse{ file ->
  relPath = file.absolutePath.substring(topDirLength).replace('\\', '/') 
  if ( file.isDirectory() && !relPath.endsWith('/')){
    relPath += "/"
  }
  entry = new ZipEntry(relPath)
  entry.time = file.lastModified()
  zipOut.putNextEntry(entry)
  if( file.isFile() ){
    zipOut << new FileInputStream(file)
    zipOut.closeEntry()
 }
}
zipOut.close()
 
} catch (Exception e) {
	e.printStackTrace()
}
return true | 
Partager