Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Zip folder with ScriptMaster

Featured Replies

The Zip File function included with the ScriptMaster sample file only works for files, not folders. Does anyone happen to have working code that works for zip-compressing a folder (including subfolders)?

Hi David,

  I don't have a module written for this but here is a stackoverflow case that has a few viable examples for accomplishing this in Java that could be modified to work as a ScriptMaster module. I think the one using the ZeroTurnaround library might be the easiest one to implement. Hope that helps!

  • Author

Thanks Ryan - looks promising. I'll post back with sample code if/when I get that set up and working.

David

this works... just native Java, no library required..

 

// ZipFilesOrDirectory( fm_fileIn ; fm_dirIn ; fm_fileOut )
// 15_10_02 JR
// v2.0
// adds list of files to fm_fileOut from fm_dirIn
// or zips a whole directory fm_dirIn to fm_fileOut

import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import java.text.Normalizer
import java.text.Normalizer.Form


SEP = System.getProperty('file.separator')
fm_dirIn = fm_dirIn[-1] == SEP?fm_dirIn : fm_dirIn + SEP

if (!fm_fileIn){
	if (fm_fileOut.contains(fm_dirIn)) {
		return 'ERROR - can\'t recurse'
	} // end if
	try {
		topDir = new File(fm_dirIn) 
		zipOut = new ZipOutputStream ( new FileOutputStream(fm_fileOut))
	
		topDirLength = topDir.absolutePath.length() +1
	
		topDir.eachFileRecurse { file ->
			relPath = file.absolutePath.substring(topDirLength).replace('\\', '/')
			if (file.isDirectory() && !relPath.endsWith('/')) {
				relPath += '/'
			} // end if
			if(relPath[0] =='.'){} else {
				entry = new ZipEntry(relPath)
				entry.time = file.lastModified()
				zipOut.putNextEntry(entry)
				if (file.isFile()) {
					zipOut << new FileInputStream(file)
				} // end if
			} //end if
			
			zipOut.closeEntry()
		} // end each
		zipOut.close()
	}
	catch(Exception e) {
		return e.getMessage()
	} //end try
	return true
	
} else {
	files = fm_fileIn.split('\n')
	byte[] buffer = new byte[1024]
	zout = new ZipOutputStream(new FileOutputStream(fm_fileOut))
	files.each{ item ->
		fin = new FileInputStream( adjust(fm_dirIn + "${item}") )
		zout.putNextEntry(new ZipEntry( adjust("${item}") ))
		while ((len = fin.read(buffer)) > 0){
			zout.write(buffer, 0, len)
		} //end while
		zout.closeEntry()
		fin.close()
	} //end each
	try{
		zout.close()
	} catch (e) {
		return e.getMessage()
	} //end try
	return true

} //end if

 

  • Author

Thanks John - I was sort of counting on you here ;-) Impeccable, as always - remind me to buy you an appropriate beverage in Montréal!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.