User Tools

Site Tools


Zip Extract All

Summary

Below is an example demonstrating how you can extract the contents of a zlib compressed (*.zip) file.

API Areas of Interest

Example

File_Zip_ExtractAll.dsa
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
 
	/*********************************************************************/
	// String : A function for retrieving a translation if one exists
	function text( sText )
	{
		// If the version of the application supports qsTr()
		if( typeof( qsTr ) != "undefined" ){
			// Return the translated (if any) text
			return qsTr( sText );
		}
 
		// Return the original text
		return sText;
	};
 
	/*********************************************************************/
	// If the application version is less than 4.9.3.149
	if( App.version64 < 0x0004000900030095 ){
		// Provide feedback
		MessageBox.information(
			text( "This script requires %1 4.9.3.149 or newer to continue." )
				.arg( App.appName ), text( "Version Error" ), text( "&OK" ) );
		// We are done..
		return;
	}
 
	// Define the source directory path
	var sSourcePath = "c:/temp";
 
	// Create a directory object
	var oDir = new DzDir( sSourcePath );
	// Get whether or not the directory exists
	var bExists = oDir.exists();
 
	// If the directory doesn't exist
	if( !bExists ){
		// Provide feedback
		print( sSourcePath, "does not exist!" );
		// We are done...
		return;
	}
 
	// Define the target directory path
	var sTargetPath = "c:/temp";
 
	// Create a directory object
	oDir = new DzDir( sTargetPath );
	// If the directory doesn't exist
	if( !oDir.exists() ){
		// Create all the missing directories in the path
		oDir.mkpath( sTargetPath );
	}
 
	// Define the basename of the zip file
	var sBasename = "ShaderBuilder";
 
	// Create a zip file object
	var oZipFile = new DzZipFile( String("%1/%2_Backup.zip").arg( sSourcePath ).arg( sBasename ) );
	// If the file doesn't exist
	if( !oZipFile.exists() ){
		// Provide feedback
		print( oZipFile.filePath(), "does not exist!" );
		// We are done...
		return;
	}
 
	// Open the zip file for reading
	oZipFile.open( DzZipFile.ReadOnly );
 
	// Extract all the files from the zip
	oZipFile.extractAll( String("%1/%2").arg( sTargetPath ).arg( sBasename ) );
 
	// Close the zip file
	oZipFile.close();
 
// Finalize the function and invoke
})();