Skip to content

Instantly share code, notes, and snippets.

@DaneWeber
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DaneWeber/d98e418f521e68632878 to your computer and use it in GitHub Desktop.
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
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%
@DaneWeber
Copy link
Author

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

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