Last active
August 29, 2015 14:27
-
-
Save DaneWeber/d98e418f521e68632878 to your computer and use it in GitHub Desktop.
Use 7Zip on each file within a directory, saving the resulting archives to a new directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InputBox, password, Enter Password for Archives, The generated archives will be protected with the password you enter below. Your input will be masked., hide | |
; Using FileSelectFolder is just one way of choosing your folders. | |
FileSelectFolder, sourcepath,,, Source Folder | |
sourcepath := RegExReplace(sourcepath, "\\$") ; Removes the trailing backslash, if present. | |
FileSelectFolder, destinationpath,,, Destination Folder | |
destinationpath := RegExReplace(destinationpath, "\\$") ; Removes the trailing backslash, if present. | |
sourcelen := StrLen(sourcepath) + 1 ; Determine the start of the variable part of the path. | |
Loop, Files, %sourcepath%\*.*, R | |
{ | |
varfilepath := SubStr(A_LoopFileFullPath, sourcelen) ; Grab everything to the right of the source folder. | |
RunWait, "c:\program files\7-zip\7z.exe" a "%destinationpath%%varfilepath%.7z" "%A_LoopFileFullPath%" -p"%password%" -t7z -mx0 -mhe -mmt,, Hide | |
FileCount := a_index | |
} | |
Msgbox Archives Created: %FileCount%`nSource: %sourcepath%`nDestination: %destinationpath% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The 7Zip flags are from the Super User question I was answering when I wrote this. The main value here is just as an example of the Loop, Run, StrLen, and SubStr commands. http://superuser.com/questions/959130/batch-file-to-create-7z-archive-for-each-file-in-folder-subfolder-to-a-new-de/959743