Problems with "7za.exe wrapper" from Scripts

Get help with using AutoHotkey and its commands and hotkeys
Peter2
Posts: 258
Joined: 21 Sep 2014, 14:38
Location: CH

Re: ZipFile [AHK v1.1 and AHK v2.0]

11 Jan 2017, 13:30

Hi

Win 10, AHK 1.1.24.02

at the moment I have problems with the 7za-wrapper. I have the AHK-coe(snippet):

Code: Select all

    FileSelectFolder, sicherungsquelle, *%A_Scriptdir%, 0,Verzeichnis zum Sichern wählen
    FileList =  ; Initialize to be blank.
    Loop Files, %sicherungsquelle%\*.*, DFR
        FileList = %FileList% %A_LoopFileFullPath%`n
    sicherungsziel = D:\xxx\rein.7z
;    7z_list(sicherungsziel)
    7z_compress(sicherungsziel,FileList)

My list of executed lines is:

Code: Select all

078: FileSelectFolder,sicherungsquelle,*%A_Scriptdir%,0,Verzeichnis zum Sichern wählen (5.20)
079: FileList = 
080: Loop,Files,%sicherungsquelle%\*.*,DFR
081: FileList = %FileList% %A_LoopFileFullPath%

081: FileList = %FileList% %A_LoopFileFullPath%

082: sicherungsziel = D:\xxx\rein.7z
084: 7z_compress(sicherungsziel,FileList)  
111: flist := ""
112: For each,file in files
113: flist := flist """" file """" " "
114: if FileExist(dPack)  
116: RunWait,%7z_exe% a -t7z "%dPack%" %flist%,,Hide UseErrorLevel
117: Return,!7z_error(ErrorLevel)
166: if (e==1)  
168: if (e==2)  
170: if (e==7)  
172: if (e==8)  
174: if (e==255)  
176: Return,e
At the end my variables are

Code: Select all

Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
7z_exe[0 of 0]:  
Beendebutton[0 of 0]:  
ErrorLevel[1 of 7]: 0
FileList[36 of 63]: D:\123\mark.mnr
 D:\123\ZipFile.ahk

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]:  

But - nothing happens. No error, but no resulting file. What could be wrong?
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
User avatar
joedf
Posts: 7730
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ZipFile [AHK v1.1 and AHK v2.0]

11 Jan 2017, 22:03

Ahh you're using the wrapper i posted here: https://autohotkey.com/boards/viewtopic ... 075#p21075

It seems that "7z_exe" has no assigned value in your script...
Do you have the "7za.exe" executable somewhere in your script's folder?
Peter2
Posts: 258
Joined: 21 Sep 2014, 14:38
Location: CH

Re: ZipFile [AHK v1.1 and AHK v2.0]

12 Jan 2017, 01:40

The code is taken from your posting above, but I think it is the same.
Yes, 7za.exe is in the folder, and it is found with FileExist.
7za is also working fine when I start it in CMD-window.
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
Peter2
Posts: 258
Joined: 21 Sep 2014, 14:38
Location: CH

Re: ZipFile [AHK v1.1 and AHK v2.0]

12 Jan 2017, 03:16

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
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
User avatar
joedf
Posts: 7730
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ZipFile [AHK v1.1 and AHK v2.0]

12 Jan 2017, 12:02

hmmm, well there shouldnt be any line feed...
A simpler method would probably be to create a new folder and make a copy of all the files you want in the archive and 7zip that folder.
So no need for a seperate batch-file, just use a single runwait line to compress this new folder.
Guest
Posts: 56
Joined: 17 Oct 2013, 02:32

Re: ZipFile [AHK v1.1 and AHK v2.0]

12 Jan 2017, 15:56

I would use the @listfiles method - create a text file in ahk, pass it on to 7z and you're done.
https://sevenzip.osdn.jp/chm/cmdline/sy ... m#ListFile

( Edit: this 7z discussion should be split from this thread as it has nothing to do with ZipFile by coco. )
Peter2
Posts: 258
Joined: 21 Sep 2014, 14:38
Location: CH

Problems with "7za.exe wrapper" from Scripts

13 Jan 2017, 12:18

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
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx
User avatar
joedf
Posts: 7730
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ZipFile [AHK v1.1 and AHK v2.0]

16 Jan 2017, 09:35

Hmmmm.... have you tried what Guest suggested?
Guest wrote:I would use the @listfiles method - create a text file in ahk, pass it on to 7z and you're done.
https://sevenzip.osdn.jp/chm/cmdline/sy ... m#ListFile
Peter2
Posts: 258
Joined: 21 Sep 2014, 14:38
Location: CH

Re: Problems with "7za.exe wrapper" from Scripts

18 Jan 2017, 15:48

Not at the moment - I will continue in a few days.
Peter (AHK Beginner) / Win 7 x64, AHK Version v1.1.22.xx

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, f1ster, GamesOfFreak, Google [Bot], malcev, mikeyww, SteveB123 and 49 guests