Difference between revisions of "7z All Files"
Line 40: | Line 40: | ||
[[Category: Scripts]] | [[Category: Scripts]] | ||
+ | [[Category: JScript Scripts]] |
Revision as of 16:05, 7 May 2018
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.
Source
// Copyright 2015, Dean Tersigni. // This program zips every file and folder in the executed directory into it's 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 != "7Z All Files.js" ) { // Don't compress this file. var sFileStem = JustStem( 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. //oFile.Delete( sFile ); } } // Returns the name of a file without the extension. function JustStem( sFileName ) { var iRight = sFileName.lastIndexOf( "." ); var sStem = sFileName.substr( 0, iRight ); return( sStem ); }