Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:27
What would you like to do?
Use 7Zip on each file within a directory, saving the resulting archives to a new directory
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%
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment