Commandline Zip - progressbar - logfile - 7z or 7zG Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

Post by Smile_ » 12 May 2020, 14:08

Have to look at it. The only thing is that you should add an error handling - if someone has opened and locked one of the result files and this should be handled differently, it can be a bit tricky to handle with a loop.
If you mean about editing the script, just compile it, AHK script -> Standalone Executable.
Found an "error" in this test code (mtee /+ "c:\temp\InfoFile.txt") must in this case be (mtee "c:\temp\InfoFile.txt")
What error?
Is it possible - instead of redirecting the result to a file - redirecting the result to a variable - but it may be another question.
You wanted to show the result on CMD window and append it to log file and you got that, in CMD commands it is possible to redirect the output into variable but it gonna make the CMD blank, at the moment I D K clear way to do that, it is not so important I think.

Improvement suggestion:
1 - You display the error output inside notepad, I think if you display it in Msgbox like the last MsgBox would be better and make Error sound when message displayed with an Error Icon.
You can find more here :arrow: https://www.autohotkey.com/docs/commands/MsgBox.htm
2 - The script doesn't use GUI interface, why you don't add one, better graphics and smoother to use and more clearer.
That GUI let the user choose the compressor executable and files to compress or folders and name of file to compress into... etc.
Plus a log box inside the GUI display the user what is happening for example if the program compressing, it displaying " Compressing Squid2 into 7zipSquid.7z ... (Size 100 MB) ".
Plus the other stuffs buttons, and texts ...

Albireo
Posts: 1748
Joined: 16 Oct 2013, 13:53

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

Post by Albireo » 12 May 2020, 16:24

Found an "error" in this test code (mtee /+ "c:\temp\InfoFile.txt") must in this case be (mtee "c:\temp\InfoFile.txt")
/+ Requires that the zip file (result file) already exists. (does not always occur).

7-zip compress as function() in AHK (Swedish version)
This version is the beginning of a result to manage zip files. (unfortunately in Swedish). Some can probably be simplified and other things should be added. (Requires external software to be installed).
The function() above, is only to compress files with 7-zip.
The strategy is to try prevent problems before the 7-zip program is run - Passwords and exe-files are checked, result files are deleted, etc. (instead of 7-zip handling any problems.)
After 7-zip has been runned, the errors, as may have occurred during program execution, is checked and handled.
Finally, the result / error file / logfile should be handled.

One thing, I don't like (right now) is the end of the function() ( the result handling )
Now 7-zip is create a result-file and an error-file like this.
- If the error file is empty - remove the file (directly).
- Read the resultfile
- Delete the resultfile
- Add run information to the result file (in the beginning)
- Create the new resultfile

Missing information
- Number of files and the sum of the original files size.

I think the best way (right now) is to test the zip result with 7-zip.
- Create a separate result file (with more customized information)
- Read the file (with all compressed file names) and get the number of files and total size.
- Delete these files
- Add this information (and maybe some statistic) to the result file above.
Examples of analyzing one 7-zip file
(Here too, problems can be created that should be dealt with)
What I do not like about this solution, is to create and delete a lot of files to achieve the result I want.

Have found some solutions, but not really known that I have any idea of how these could work together with 7-zip / Mtee.
One is (as works!) .:
The function CMDret()
Another (old one) is .: StdoutToVar (but I don't find the AHK-program)

The Result from function
From the zip-function() .: Information about the AHK program / date and time / run time / compression etc. should be returned to the main program, to save in a "main-logfile" (maybe in an object)

When the 7zip-compress program is work as desired, it is time to unzip compressed files, (probably in a separate function() - or if it might be possible to insert in the same function()) - but I'm not sure it will work. (and maybe look at 7-zip test / list and so on...)

thebbandit
Posts: 45
Joined: 02 Jul 2019, 11:34

Re: Commandline Zip - progressbar - logfile - 7z or 7zG

Post by thebbandit » 20 Jun 2021, 17:17

just want to acknowledge how helpful this thread was to zip the contents of a folder into an archive, while skipping the folder that contains the backups. I will be working on further improving this version of the code by converting it into a function... but nonetheless, I have not done that yet so here is this for anyone who might find this useful, while I remember! :P

Code: Select all

ExeFile = %A_ScriptDir%\7za.exe
RunArgs = a -w"%A_ScriptDir%" -t7z -x!Backup\
ToZip = %A_ScriptDir%\Backup\%A_Now%.7z
SourceFile = .\*
Output = %A_ScriptDir%\7zip.txt
Mtee = %A_ScriptDir%\Mtee.exe

RunWait %comspec% /c " "%ExeFile%" %RunArgs% "%ToZip%" "%SourceFile%" | "%Mtee%" /+ "%Output%" ",, UseErrorLevel, ZipPID
RunWait, %Output%
The files are just placed in the script folder for portability

Edit:
Here is the quick class I made to handle backup & restore of a script to Backup folder.
It also will install the script from source from w/e repository you assign in the static values

Code: Select all

Class 7za {
	Static ExeFile := A_ScriptDir "\data\7za.exe"
	Static AddArgs := "a -w""" A_ScriptDir """ -t7z -x!Backup\"
	Static SourceFile := ".\*"
	Static LogOutput := A_ScriptDir "\logs\Archive.log"
	Static Mtee := A_ScriptDir "\data\Mtee.exe"
	Static Source := A_ScriptDir "\data\source.zip"
	backup(){
		ToZip := A_ScriptDir "\Backup\" A_Now ".7z"
		RunWait % comspec " /c "" """ This.ExeFile """ " This.AddArgs " """ ToZip """ """ This.SourceFile """ | """ This.Mtee """ /D/T/+ """ This.LogOutput """ """,, hide UseErrorLevel, ZipPID
	}
	restore(date){
		loc := A_ScriptDir "\Backup\" date ".7z"
		If FileExist(loc){
			ExtArgs := "x """ loc """ -o""" A_ScriptDir """ -y"
			RunWait % comspec " /c "" """ This.ExeFile """ " ExtArgs " | """ This.Mtee """ /D/T/+ """ This.LogOutput """ """,, hide UseErrorLevel, ZipPID
		}
	}
	install(branch){
		Static Acc := "BanditTech"
		Static Proj := "WingmanReloaded"
		Link := "https://github.com/" Acc "/" Proj "/archive/refs/heads/" branch ".zip"
		; UrlDownloadToFile,% Link,% This.Source
		ExtArgs := "x """ This.Source """ -o""" A_ScriptDir """ -y"

		subfolder := Proj "-" branch
		RunWait % comspec " /c "" """ This.ExeFile """ " ExtArgs " | """ This.Mtee """ /D/T/+ """ This.LogOutput """ """,, hide UseErrorLevel, ZipPID

		MoveArgs := "ROBOCOPY " subfolder " /S /IS """ A_ScriptDir """ /MOVE"
		RunWait % comspec " /c " MoveArgs,,hide

		RemoveArgs := "rmdir /s /q " subfolder
		RunWait % comspec " /c " RemoveArgs,,hide

	}
}
edit2: Even found out you can hide the console window popup as well with AHK :D

Post Reply

Return to “Ask for Help (v1)”