Difference between revisions of "7z All Files"

From TheAlmightyGuru
Jump to: navigation, search
 
Line 1: Line 1:
'''''7z All Files''''' is a [[JScript]] program that uses [[7-Zip]] to compress every individual file in the folder in which the script is executed into a 7z compressed file using optimal compression settings. You must have 7-Zip installed on your computer. If the path is different than the source, simply change the path in the code.
+
'''''7z All Files''''' is a [[JScript]] program that uses [[7-Zip]] to compress every individual file in the folder in which the script is executed into a [[7Z]] compressed file using optimal compression settings. You must have 7-Zip installed on your computer. If the path is different than the source, simply change the path in the code. This script is similar to [[7z All Folders]].
 +
 
 +
To use the program, copy and paste the following source code into a file named "7z all files.js", then move the file into the folder you want and double-click it. Every file in the folder will be compressed into a 7Z file with the same name as the file.
  
 
==Source==
 
==Source==

Latest revision as of 13:10, 30 April 2024

7z All Files is a JScript program that uses 7-Zip to compress every individual file in the folder in which the script is executed into a 7Z compressed file using optimal compression settings. You must have 7-Zip installed on your computer. If the path is different than the source, simply change the path in the code. This script is similar to 7z All Folders.

To use the program, copy and paste the following source code into a file named "7z all files.js", then move the file into the folder you want and double-click it. Every file in the folder will be compressed into a 7Z file with the same name as the file.

Source

// Copyright 2015-2020, Dean Tersigni.
// This program zips every file and folder (that isn't already a 7z file) in the executed directory into its own individual zip file.
// It requires that 7-Zip be installed at "C:\Program Files\7-Zip".

var oFSO = new ActiveXObject( "Scripting.FileSystemObject" );
var oWSH = new ActiveXObject( "WScript.Shell" );

var sFolder = oWSH.CurrentDirectory;						// Get the current folder.
var oFolder = oFSO.GetFolder( sFolder );					// Create an object reference to the current folder.
var oFiles = oFolder.files;							// Get a file object based on all the files.

var eFiles = new Enumerator( oFiles );						// Create an enumerator on the file object.

var sFilePath;
for( ; !eFiles.atEnd(); eFiles.moveNext() ) {					// Loop through the files.
 	oFile = eFiles.item();							// Get the path of the current file.
	
	var sFile = oFile.Name;							// Get the file name.
	
	if( sFile.toLowerCase() != "7z all files.js" ) {			// Don't compress this file.
		if( GetExtension( sFile ).toLowerCase() != "7z" ) {

			var sFileStem = GetFileNameWithoutExtension( sFile );	// Get the file name without its extension.
			
			var sNewFile = sFileStem + ".7z";
			
			oWSH.run('"C:\\Program Files\\7-Zip\\7z.exe" a "' + sNewFile + '" "' + sFile + '" -t7z -mx9 -ms=30f10m -mhc=on -r', 0, true);
			// Delete the old file. Uncomment the following line to have the program clean up after itself,
			// otherwise, you'll have to do it yourself.
			//oFile.Delete( sFile );
		}
	}
}

// Returns the name of a file without the extension.
function GetFileNameWithoutExtension( sFileName ) {
	var iRight = sFileName.lastIndexOf( "." );
	var sStem = sFileName.substr( 0, iRight );
	return( sStem );
}

// Returns the extension of a file path.
function GetExtension( sFileName ) {
	var iLeft = sFileName.lastIndexOf( "." );
	var sExtension = sFileName.substr( iLeft + 1 );

	return( sExtension );
}