Thread is forked from here: ZipFile [AHK v1.1 and AHK v2.0]
https://autohotkey.com/boards/viewtopic.php?f=6&t=3892
------------------------------
joedf posted this 7za.exe wrapper in the topic above:
Code: Select all
;7z warpper - joedf
7z_exe:="7za.exe"
7z_compress(dPack,files*) {
global 7z_exe
flist:=""
for each, file in files
flist:= flist """" file """" " "
if FileExist(dPack)
FileDelete, %dPack%
RunWait, %7z_exe% a -t7z "%dPack%" %flist%,,Hide UseErrorLevel
return !7z_error(ErrorLevel)
}
7z_extract(dPack,dFolder="",opts="") {
global 7z_exe
if StrLen(dFolder)
out:="-o" . """" . dFolder . """"
RunWait, %7z_exe% x "%dPack%" %out% -y %opts%,,Hide UseErrorLevel
return !7z_error(ErrorLevel)
}
7z_list(dPack) {
global 7z_exe
tmp:=TempFile()
RunWait,%comspec% /c %7z_exe% l "%dPack%" > "%tmp%",,Hide UseErrorLevel
r:={}
if (!(e:=7z_error(ErrorLevel))) {
FileRead,o,%tmp%
Loop, Parse, o, `n, `r
{
if (RegExMatch(A_LoopField,"(-+\s+){4}")) {
if (!i)
i:=A_Index
else
break
}
if (A_Index-i > 0) {
p:=StrSplit(A_LoopField,A_Space)
RegExMatch(SubStr(A_LoopField,StrLen(p.1 p.2 p.3)+3),"\d+",S)
c:=InStr(A_LoopField,S)+StrLen(S)
StringTrimLeft,n,A_LoopField,%c%
k:={}
k.Date := p.1
k.Time := p.2
k.Attr := p.3
k.Size := S
k.Name := RegExReplace(n,"\s+\d*\s+","","",1)
r.Insert(k)
}
}
}
FileDelete,%tmp%
return (e?0:r)
}
7z_error(e) {
if (e==1)
MsgBox Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed.
else if (e==2)
MsgBox Fatal error
else if (e==7)
MsgBox Command line error
else if (e==8)
MsgBox Not enough memory for operation
else if (e==255)
MsgBox User stopped the process
return e
}
TempFile() {
Loop
tempName := A_Temp "\~temp" A_TickCount ".tmp"
until !FileExist(tempName)
return tempName
}
I have problems with the "compress-function", here's my last post:
Some steps more, but no solution.
Yes, "7z_exe" had no value, so I moved it into the function. I also made a lot of (simple) intermediate steps to report and see what it does.
Here is the (ugly) code:
Code: Select all
7z_compress(dPack,files*) {
global 7z_exe
global xx
global flist
7z_exe := "7za.exe"
flist:=""
for each, file in files
; flist:= flist """" file """" " "
flist:= flist file
if FileExist(dPack)
FileDelete, %dPack%
xx = %7z_exe% a -t7z %dPack% %flist%
FileDelete, %A_Scriptdir%\code.bat
FileAppend , %xx%, %A_Scriptdir%\code.bat
msgbox %xx%
RunWait, %xx%,,Hide UseErrorLevel
return !7z_error(ErrorLevel)
}
Here are the executed lines:
Code: Select all
080: FileSelectFolder,sicherungsquelle,D:\123,0,Verzeichnis zum Sichern wählen (1.75)
094: FileList =
095: Loop,Files,%sicherungsquelle%\*.*,DFR
096: FileList = %FileList% %A_LoopFileFullPath%
096: FileList = %FileList% %A_LoopFileFullPath%
096: FileList = %FileList% %A_LoopFileFullPath%
096: FileList = %FileList% %A_LoopFileFullPath%
096: FileList = %FileList% %A_LoopFileFullPath%
096: FileList = %FileList% %A_LoopFileFullPath%
097: sicherungsziel = D:\xxx\rein.7z
099: 7z_compress(sicherungsziel,FileList)
151: 7z_exe := "7za.exe"
152: flist := ""
153: For each,file in files
155: flist := flist file
156: if FileExist(dPack)
157: FileDelete,%dPack%
158: xx = %7z_exe% a -t7z %dPack% %flist%
159: FileDelete,%A_Scriptdir%\code.bat
160: FileAppend,%xx%,%A_Scriptdir%\code.bat
161: MsgBox,%xx% (1.16)
162: RunWait,%xx%,,Hide UseErrorLevel (0.05)
163: Return,!7z_error(ErrorLevel)
212: if (e==1)
213: MsgBox,Warning (Non fatal error(s)). For example, one or more files were locked by some other application, so they were not compressed. (1.30)
222: Return,e
101: Return (82.89)
here are the variables after execution:
Code: Select all
Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
7z_exe[7 of 7]: 7za.exe
Beendebutton[0 of 0]:
ErrorLevel[1 of 3]: 0
ersatz_ziel[0 of 0]:
FileList[130 of 259]: D:\123\DOSLib19x64.arx
D:\123\DOSLib20.arx
D:\123\DOSLib20...
flist[130 of 259]: D:\123\DOSLib19x64.arx
D:\123\DOSLib20.arx
D:\123\DOSLib20...
OutFileName[0 of 0]:
Sichern[0 of 0]:
sicherungsquelle[6 of 7]: D:\123
sicherungsziel[14 of 63]: D:\xxx\rein.7z
updatefile[0 of 0]:
Updaten[0 of 0]:
versionsdatum_str[10 of 63]: 30.01.2017
wiederherst_quelle[0 of 0]:
wiederherst_ziel[0 of 0]:
Wiederherstellen[0 of 0]:
xx[160 of 259]: 7za.exe a -t7z D:\xxx\rein.7z D:\123\DOSLib19x64.arx
D:\123...
Here is the Batch-file I create (yes - with line feed)
Code: Select all
7za.exe a -t7z D:\xxx\rein.7z D:\123\DOSLib19x64.arx
D:\123\DOSLib20.arx
D:\123\DOSLib20x64.arx
D:\123\DOSLib21.arx
D:\123\DOSLib21x64.arx
D:\123\mark.mnr
The result:
- It creates the 7z-file, but only with the last file from the file-list
- Then it shows the error message "Warning (Non fatal error(s)). For example, one or more files were locked by some ...."
- When I start the bat-file, it only packs the first file (from the first line). That is obvious.
- When I modify the bat-file to one single line, then it works fine