AutoHotKey to the rescue! Limiting yourself to the Windows command line is painful. Since you mentioned that you intend to do this loop in conjunction with AutoHotKey, why not just use AutoHotKey for the whole thing?
Use StrLen and SubStr to extract the variable portion of your file path. The file loop will recurse through all the files you want. And then it's just a matter of using RunWait to pass the paths you've generated to 7-Zip. The
,, Hide specified at the end of the
RunWait tells it to hide the command windows spawned.
Here's an example script that includes the ability to choose source and destination folders via the GUI:
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.
; This is the meat of the answer:
sourcelen := StrLen(sourcepath) + 1 ; Determine the start of the variable part of the path.
Loop, Files, %sourcepath%\*.*, R ; Here's the replacement for your batch file loop.
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%
Note that you need v1.1.21+ of AHK or above for the file loop to operate as written.