Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 04 Jul 2021, 04:30

Hi, just joined up to ask this specific question for a problem I needed solving.

I am in need of automating a huculean task: zipping two files in a folder of 12, resulting in two files into one zipped file, which is easy to do with the "Right Click/Send to/Compressed (Zipped)" manner, but it was slow, so I just uses the Zip icon in the windows exploerer and it was much faster but not by much.

So I zipped two by two by two by two, by selecting two files at a time, clicking on the Zip icon, 12 times for each folder.

I'll be processing through about 8 thousands files, the jpgs, then the exported pdfs, which I finished recently, now zipping up both files at a time. It is slow and tedious. It is my artwork jpgs and pdf files.

In searching online, I almost found the answer, but testing the code results in weird results.

In this webpage: https://superuser.com/questions/1077785/create-send-to-compressedzipped-folder-event-shortcut-on-windows10

The guy's solution was this:

Code: Select all

#IfWinActive ahk_class CabinetWClass ; Only run AutoHotkey script when Windows explorer has the focus
z::                     ; Keyboard shortcut z
Send, {AppsKey}         ; Press the "context menu" key
Sleep 100
Send n                  ; Select "Send to" with the "n" key
Sleep 100
Send {Right}            ; Open "Sent to" with the "right arrow" key
Sleep 100
Send {Down}             ; Select "Compressed (zipped) folder" with the "arrow down" key
Sleep 100
Send {Enter}            ; Execute "Compressed (zipped) folder" with the "Enter" key
return
But in testing it, when I presses "Z", the dialog that shows up is DropBox which thinks I wants to share the two files. So I exited the Dropbox and what happens when I try again? Windows Security dialog shows up.

How do I links the Windows Compressed (Zipped) Folder to the shortcut "z" so I can automated this for the job?

Looking up the AutoHotKey's scripts, functions, etc it's all bewildering and confusing.

So I thought to ask here, if someone might have solve this problem a long time ago, perhaps they could share the script, and could let me have it? It is for this one purpose, only.

After the job, I'll uninstall AutoHotKey and delete the script, never using it ever again. I won't likely need it any more in future.

Is there anyone who has this or could revise the script above?

I would greatly appreciates any help in this matter.

Thank you, regards.

User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by mikeyww » 04 Jul 2021, 06:38

I would look to see whether there is a command line that you can use instead. I imagine that 7zip could do it. You could then just send your selection via the command line.

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 04 Jul 2021, 07:13

Not sure what this command line is. Windows prompt? Not knowledgeable about it, tho.

What I can do is show you what I mean.

Image

Zipping jpg and pdf files, 12 zips per folder

Image

A lot of folders to go through. This is one gruop. I got three more groups to go through exactly like this one. Just jpg alone is about 2,000 for one group. I made pdfs as well, so that's 4,000 for this one group. Three more groups, 6,000 to go.

Command line seems tedious too.

I had though, I would use the mouse to select the files as needed, then just presses the "z" key and hey presto done. Repeat as need, then get all others done as well.

That's all I needed to do.

I was hoping AutoHotKey could have a script for that. I guess not.

I was just looking to see if there's a way, but I guess there's only the Windows way, oh well.

Thanks for your suggestions, I appreciates it, very much.

Regards

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by WatsonEnterprises » 04 Jul 2021, 15:21

You could do them all at once instead of manually selecting each one, by looping through all your files/folders and sending them to 7zip/Winrar/whatever.

https://www.autohotkey.com/docs/commands/LoopFile.htm

This will do what you want using 7zip commandline. Pass your parent folder to the function (In this case, probably "KIZZ 1 Full Colours"). And point programPath to wherever you installed 7zip.

Code: Select all

DoZips("C:\testFolder")
return

DoZips(directory){
	for _, file in AllFilesIn(directory, "jpg", "R") {  ;R for recursive
		SplitPath, file, name, dir, ext, nameNoExt, drive
		
		fileJPG := file
		filePDF := dir "\" nameNoExt ".pdf"
		outputZipPath := dir "\" nameNoExt ".zip"
		
		if (FileExist(fileJPG) && FileExist(filePDF))
			SendToZippingProgram(fileJPG, filePDF, outputZipPath)
	}
	msgbox % "Done"
}
AllFilesIn(directory, extension:="*", mode:=""){
	filesArray := Array()
	Loop, Files, % (filepattern := directory "\*." extension), % mode
		filesArray.Push(A_LoopFileLongPath)
	return filesArray
}


SendToZippingProgram(file1, file2, outputZipPath){
	msgbox % "I'm going to zip`r`n`r`n" file1 "`r`nand`r`n" file2 "`r`n`r`nto`r`n" outputZipPath
	
	programPath := "C:\Program Files\7-Zip\7zG.exe"
	RunWait, % InQuotes(programPath)   A_Space   "a" A_Space InQuotes(outputZipPath)   A_Space   InQuotes(file1) A_Space InQuotes(file2)
	;https://sevenzip.osdn.jp/chm/cmdline/commands/add.htm
}
InQuotes(str){
	return """" str """"
}

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 05 Jul 2021, 01:36

Thank you for your suggestions, however, I don't think you realise the implications of this huge undertaking.

The Full Colour folder containing 186 folders of about 2,000 jpgs and 2,000 pdfs, and they all adds up to 10 GB in file size, and if zipping, it would take hours, maybe days, to finishes zipping just one time. I don't want one giant zip of this 10 GB... no, I needs one zip of each jpg and pdf, do you follow?

I plans on selling one jpg and one pdf file, as an artwork print on demand. So I'm zipping these two up, one by one.

I'll adds licensing pdf file to each of these zipped files, later.

White Background and Black background folders is around 5 GB each. JPGs and PDFs formats files.

The Transparent folder is around 10.9 GB. PNGs and TIFs formats files.

So, I have to zips two files 12 times per folder in each of those folders.

What I had in mind with the AutoHotKey is this:

I selects the two desired files, a jpg and a pdf, as you can see in the picture above, and then presses the "z" key to zip the two into one zip file. That's it. Nothing else. Zip two at a time, zip, zip, zip. I do this 12 times each folder.

I don't mind the time it takes me, as long as I can do it fast, all I require is the ability to zip as fast as 12 times per folder, bam bam bam, done done done.... that's what I was looking for.

It's about automating a process with as few steps as possible. My hands and arms gets tired and I have to rest often.

As it is, I'm getting the hang of selecting, with the mouse, then moving the mouse over the yellow zip icon in the ribbon above then click on it, then click on the window, finishes all 12, then right click sort them into zip files, selects all zip files, drag them over to the empty sets of folders, to add the licensing pdf file later.

Then I go back and repeat the same process with each sets of folders, all the way to 33b. Then repeat with the other three big folders.

I hopes to be finishes by next week.

So that's it. Thank you for your suggestion, I appreciates it.

Regards.

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 05 Jul 2021, 06:18

I found a webpage that talked about WinHotKey, so I tests it after downloading it and figuring out how to link the hot key (Ctrl + Z) to the Compressed (Zipped) Folder link in the AppData, etc etc and it did not work at all.

The dialog said, the application cannot be found.

So I figure it out, when I browsed for the exe file, the Compressed (Zipped) folder link are not even a real application, it's a shortcut and wherever the zipping software is, microsoft is hiding it. Sneaky sobs.

So I throws WinHotKey out and went back to mouse over to Zip and click, repeat method.

Now I'm up to Folder 25b. Awesome.

WinHotKey was easier, setting up the shortcut link to the zipping program but didn't work. I want to link it directly to the Windows Zip so it'll work in action, directly, no need for pop up dialog. smh

Oh well.

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by WatsonEnterprises » 07 Jul 2021, 00:24

highseas wrote:
05 Jul 2021, 01:36
I don't want one giant zip of this 10 GB... no, I needs one zip of each jpg and pdf
That's what my solution does. It searches every subfolder recursively, and if it finds a jpg/pdf pair with the same name, it makes a new zip containing just that pair.

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 07 Jul 2021, 02:02

WatsonEnterprises wrote:
07 Jul 2021, 00:24
highseas wrote:
05 Jul 2021, 01:36
I don't want one giant zip of this 10 GB... no, I needs one zip of each jpg and pdf
That's what my solution does. It searches every subfolder recursively, and if it finds a jpg/pdf pair with the same name, it makes a new zip containing just that pair.
Well, I tried it, all the AutoHotKey dialog shows is "Done", and I don't see any of the jpf/pdf zipped into zip files.

Even dragdropping the folders onto the green AutoHotKey thingy only same thing happens, dialog "Done", but nothing happens.

Thanks anyway, I appreciates your help with this matter.

Regards

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 07 Jul 2021, 10:29

WatsonEnterprises wrote:
07 Jul 2021, 00:24
highseas wrote:
05 Jul 2021, 01:36
I don't want one giant zip of this 10 GB... no, I needs one zip of each jpg and pdf
That's what my solution does. It searches every subfolder recursively, and if it finds a jpg/pdf pair with the same name, it makes a new zip containing just that pair.
I was wrong, mate.

I had a look at your script again and I was thinking there must be something I could do to make it work, and ... I did do something.

I took the file path from my folder that I wants to zip all the jpf/pdfs in into their own zip files... copied that path, pastes that into the place where it says "C:\testFolder" and changed that to the correct path.

The folder and files are in the external hard drive, so yeah, no wonder the script wont' work on the C: hard drive. Good thing I was thinking about how to solve it when I thought about it, lol.

Then I tested it.

And it worked.

Damn, I didn't realise, thank you for making me think.

The only problem is that I have to "OK" each dialog that comes up.

Image

As you can see, it's working perfectly.

Easy to just click "OK" or "Enter" every time the dialog comes up asking me to let it proceeds, eh.

But yeah, it's kind of a chore to make sure to "OK" it or "Enter" it to make it keep going.

I'm wondering, is this part of the design? It's there a way for it to just keep going until it finishes by the last final folder?

Thanks for making the script, it really helps. The RSI is flaring up again, so rest is mandatory.

Regards

User avatar
flyingDman
Posts: 2846
Joined: 29 Sep 2013, 19:01

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by flyingDman » 07 Jul 2021, 14:35

There is a native way to zip files in AHK: https://autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
I updated the function as it gave me errors when zipping large files. Also, the fist argument of the function is an array of file paths. Lastly, it fearures a progress bar to show the status of the operation.

So in combination with the "Explorer_GetSelected" script @mikeyww was referring to, you can do something like this:

Code: Select all

^+z::                                                      ; ctrl-shift z
arr := strsplit(Explorer_GetSelected(),"`n")
stmp := "zip" . A_Year . A_MM . A_DD "_" A_Hour . A_min . A_sec . ".zip"
InputBox, sZip, , , , 450, 150, , , , , % Explorer_GetPath() . "\" . stmp
if ErrorLevel
    return
Zip(arr,sZip)
return

Zip(FilesToZip,sZip)										; FilesToZip is an array
	{
	cnt := FilesToZip.count()
	Progress, p1 CWFFFFFF CT000000 b x750 y800 w390 FS9, % "Zipping file 1 of " cnt  		; I know, deprecated	
	If Not FileExist(sZip)
		CreateZipFile(sZip)
	psh := ComObjCreate("Shell.Application")
	pzip := psh.Namespace(sZip)
	for x,y in FilesToZip
		{
		pzip.CopyHere(y, 4|16)
		while (pzip.Items().count < x)
			sleep, 250
		Progress, % 100 * (x/cnt), % "Zipping file " pzip.Items().count + 1 . " of " . cnt   
		}
	Progress, 100, Done!
	sleep, 1000
	Progress, off
	}

CreateZipFile(sZip)
	{
	Header1 := "PK" . Chr(5) . Chr(6)
	VarSetCapacity(Header2, 18, 0)
	file := FileOpen(sZip,"w")
	file.Write(Header1)
	file.RawWrite(Header2,18)
	file.close()
	}

Explorer_GetPath(hwnd="")
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
		return A_Desktop
	path := window.LocationURL
	path := RegExReplace(path, "ftp://.*@","ftp://")
	StringReplace, path, path, file:///
	StringReplace, path, path, /, \, All 
	
	; thanks to polyethene
	Loop
		If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
			StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
		Else Break
	return path
}
Explorer_GetAll(hwnd="")
{
	return Explorer_Get(hwnd)
}
Explorer_GetSelected(hwnd="")
{
	return Explorer_Get(hwnd,true)
}

Explorer_GetWindow(hwnd="")
{
	; thanks to jethrow for some pointers here
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
	
	if (process!="explorer.exe")
		return
	if (class ~= "(Cabinet|Explore)WClass")
	{
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd==hwnd)
				return window
	}
	else if (class ~= "Progman|WorkerW") 
		return "desktop" ; desktop found
}
Explorer_Get(hwnd="",selection=false)
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
	{
		ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
		if !hwWindow ; #D mode
			ControlGet, hwWindow, HWND,, SysListView321, A
		ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
		base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
		Loop, Parse, files, `n, `r
		{
			path := base "\" A_LoopField
			IfExist %path% ; ignore special icons like Computer (at least for now)
				ret .= path "`n"
		}
	}
	else
	{
		if selection
			collection := window.document.SelectedItems
		else
			collection := window.document.Folder.Items
		for item in collection
			ret .= item.path "`n"
	}
	return Trim(ret,"`n")
}
14.3 & 1.3.7

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 07 Jul 2021, 22:49

flyingDman wrote:
07 Jul 2021, 14:35
There is a native way to zip files in AHK: https://autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
I updated the function as it gave me errors when zipping large files. Also, the fist argument of the function is an array of file paths. Lastly, it fearures a progress bar to show the status of the operation.

So in combination with the "Explorer_GetSelected" script @mikeyww was referring to, you can do something like this:

Code: Select all

^+z::                                                      ; ctrl-shift z
arr := strsplit(Explorer_GetSelected(),"`n")
stmp := "zip" . A_Year . A_MM . A_DD "_" A_Hour . A_min . A_sec . ".zip"
InputBox, sZip, , , , 450, 150, , , , , % Explorer_GetPath() . "\" . stmp
if ErrorLevel
    return
Zip(arr,sZip)
return

Zip(FilesToZip,sZip)										; FilesToZip is an array
	{
	cnt := FilesToZip.count()
	Progress, p1 CWFFFFFF CT000000 b x750 y800 w390 FS9, % "Zipping file 1 of " cnt  		; I know, deprecated	
	If Not FileExist(sZip)
		CreateZipFile(sZip)
	psh := ComObjCreate("Shell.Application")
	pzip := psh.Namespace(sZip)
	for x,y in FilesToZip
		{
		pzip.CopyHere(y, 4|16)
		while (pzip.Items().count < x)
			sleep, 250
		Progress, % 100 * (x/cnt), % "Zipping file " pzip.Items().count + 1 . " of " . cnt   
		}
	Progress, 100, Done!
	sleep, 1000
	Progress, off
	}

CreateZipFile(sZip)
	{
	Header1 := "PK" . Chr(5) . Chr(6)
	VarSetCapacity(Header2, 18, 0)
	file := FileOpen(sZip,"w")
	file.Write(Header1)
	file.RawWrite(Header2,18)
	file.close()
	}

Explorer_GetPath(hwnd="")
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
		return A_Desktop
	path := window.LocationURL
	path := RegExReplace(path, "ftp://.*@","ftp://")
	StringReplace, path, path, file:///
	StringReplace, path, path, /, \, All 
	
	; thanks to polyethene
	Loop
		If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
			StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
		Else Break
	return path
}
Explorer_GetAll(hwnd="")
{
	return Explorer_Get(hwnd)
}
Explorer_GetSelected(hwnd="")
{
	return Explorer_Get(hwnd,true)
}

Explorer_GetWindow(hwnd="")
{
	; thanks to jethrow for some pointers here
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
	
	if (process!="explorer.exe")
		return
	if (class ~= "(Cabinet|Explore)WClass")
	{
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd==hwnd)
				return window
	}
	else if (class ~= "Progman|WorkerW") 
		return "desktop" ; desktop found
}
Explorer_Get(hwnd="",selection=false)
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
	{
		ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
		if !hwWindow ; #D mode
			ControlGet, hwWindow, HWND,, SysListView321, A
		ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
		base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
		Loop, Parse, files, `n, `r
		{
			path := base "\" A_LoopField
			IfExist %path% ; ignore special icons like Computer (at least for now)
				ret .= path "`n"
		}
	}
	else
	{
		if selection
			collection := window.document.SelectedItems
		else
			collection := window.document.Folder.Items
		for item in collection
			ret .= item.path "`n"
	}
	return Trim(ret,"`n")
}
Apologies. I've tested this and nothing happens. I selected the jpg/pdf files and tried it, nothing happens too.

The other bloke's script works perfectly, I'm sorry but I'll stick with that one.

All I had to do is to put in the file path to the folders and that was it, easy peasy. Even though I have to watch and click "OK" every time to get it to keep going until the end. It's better than nothing.

Last night I tried it and it worked, finishing the White Backgrounds in about 2 hours.

Now I'll be zipping the Black Backgrounds, and after this, I'll change the jpg and pdf to png and tif files, and then zipping those.

Finally it'll all be done.

I tested many software and found FreeCommander to be superior where I can copy two pdf files to the zipped files by opening them in the two paned windows, which is awesome, and saves on time, saves on clicking all the time. I got it to a fine art now, click, paste, click, click, paste, click click, paste, and so, finally, finishing it all.

Thank you for helping, I appreciates your script, I really do, it's good work, thank you very much for helping. Much obliged.

Regards

WatsonEnterprises
Posts: 19
Joined: 25 May 2020, 23:04

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by WatsonEnterprises » 08 Jul 2021, 00:15

flyingDman wrote:
07 Jul 2021, 14:35
There is a native way to zip files in AHK
That's pretty nice. I didn't know about that.

highseas wrote:
07 Jul 2021, 10:29
it's kind of a chore to make sure to "OK" it or "Enter" it to make it keep going.
Sorry, you can remove that msgbox by deleting the "msgbox" line inside the function. I just included it to give some indication of what was going on.

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 08 Jul 2021, 03:22

WatsonEnterprises wrote:
08 Jul 2021, 00:15
flyingDman wrote:
07 Jul 2021, 14:35
There is a native way to zip files in AHK
That's pretty nice. I didn't know about that.

highseas wrote:
07 Jul 2021, 10:29
it's kind of a chore to make sure to "OK" it or "Enter" it to make it keep going.
Sorry, you can remove that msgbox by deleting the "msgbox" line inside the function. I just included it to give some indication of what was going on.
Wow, so that's how it works, thank you for the tip, I appreciates it. Will includes that.

Anyways, all done, mate.

12:35 pm, started zipping Black backgrounds folder.
2 pm, finished Black backgrounds folder.

2:04 pm, starts zipping Transparent folder.
4:11 pm, finished zipping Transparent folder.

Here's the script I edited to make it work for PNG and TIF formats.

Code: Select all

DoZips("C:\DRIVE FOLDER PATH")
return

DoZips(directory){
	for _, file in AllFilesIn(directory, "png", "R") {  ;R for recursive
		SplitPath, file, name, dir, ext, nameNoExt, drive
		
		filePNG := file
		fileTIF := dir "\" nameNoExt ".tif"
		outputZipPath := dir "\" nameNoExt ".zip"
		
		if (FileExist(filePNG) && FileExist(fileTIF))
			SendToZippingProgram(filePNG, fileTIF, outputZipPath)
	}
	msgbox % "Done"
}
AllFilesIn(directory, extension:="*", mode:=""){
	filesArray := Array()
	Loop, Files, % (filepattern := directory "\*." extension), % mode
		filesArray.Push(A_LoopFileLongPath)
	return filesArray
}


SendToZippingProgram(file1, file2, outputZipPath){
	msgbox % "I'm going to zip`r`n`r`n" file1 "`r`nand`r`n" file2 "`r`n`r`nto`r`n" outputZipPath
	
	programPath := "C:\Program Files\7-Zip\7zG.exe"
	RunWait, % InQuotes(programPath)   A_Space   "a" A_Space InQuotes(outputZipPath)   A_Space   InQuotes(file1) A_Space InQuotes(file2)
	;https://sevenzip.osdn.jp/chm/cmdline/commands/add.htm
}
InQuotes(str){
	return """" str """"
}
Thank you for providing the script, it is amazing, AutoHotKey are amazing. Sure saves time getting things done. I would have spent days doing this and yet, with this script, all's done.

Thank you and much appreciated for helping. I hopes this script helps many others solves their work.

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 08 Jul 2021, 03:39

WatsonEnterprises wrote:
08 Jul 2021, 00:15
flyingDman wrote:
07 Jul 2021, 14:35
There is a native way to zip files in AHK
That's pretty nice. I didn't know about that.

highseas wrote:
07 Jul 2021, 10:29
it's kind of a chore to make sure to "OK" it or "Enter" it to make it keep going.
Sorry, you can remove that msgbox by deleting the "msgbox" line inside the function. I just included it to give some indication of what was going on.
I just tested that, but it didn't work.

Removing the "msgbox % "Done"", it's still the same as before. So I removed the "msgbox %" from the other line, and it won't run.

It's okay, I finished anyways.

Thank you for your script, it works, that's what matters. I appreciates it.

Regards

highseas
Posts: 14
Joined: 04 Jul 2021, 03:57

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by highseas » 08 Jul 2021, 05:45

Hi WatsonEnterprises,

I was thinking while shifting the zipped files to the Zipped folders... I know I'll be getting ready to start adding the two licensing pdf files into the zipped files with the FreeCommander software, but I was thinking, what if AutoHotKey can do this easily? Is that possible?

Can AutoHotKey copy the two licensing pdf files and then pastes these two files into all the zipped files in all the White, Black and Transparent folders? All 3,000 zipped files? Is that possible?

I was just wondering if it's possible. It's okay if it's not. I'll just be using the FreeCommander to do it, albeit slowly, but man, the idea of AutoHotKey being able to do it so quickly, well, like the zipping process, it sure would be handy, alright.

Thanks for all the help here, I really appreciates it.

Regards

Update: Problem solved. No worries!

How to Paste files into multiple Zipped files on the fly?
https://www.autohotkey.com/boards/viewtopic.php?f=76&t=92467

Thank you AutoHotKey forum members, for making life easier with awesome scripts. Much appreciated.

Regards

lyscop
Posts: 14
Joined: 18 Dec 2021, 20:26

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by lyscop » 19 Dec 2021, 06:17

flyingDman wrote:
07 Jul 2021, 14:35
There is a native way to zip files in AHK: https://autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
I updated the function as it gave me errors when zipping large files. Also, the first argument of the function is an array of file paths. Lastly, it features a progress bar to show the status of the operation.

So in combination with the "Explorer_GetSelected" script @mikeyww was referring to, you can do something like this:
Thank you for the nice shortcut code.

There is a problem that I do the shortcut action on the different foreground windows to zip the file or fold, the result is different.

On desktop, it works well, and on the fold like D:/Myfiles works well too.

But on the fold D:/, no matter which type file or fold I select, it broke, and the progress bar is dead at the beginning.

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by Avastgard » 23 Jan 2023, 15:45

flyingDman wrote:
07 Jul 2021, 14:35
There is a native way to zip files in AHK: https://autohotkey.com/board/topic/60706-native-zip-and-unzip-xpvista7-ahk-l/
I updated the function as it gave me errors when zipping large files. Also, the fist argument of the function is an array of file paths. Lastly, it fearures a progress bar to show the status of the operation.

So in combination with the "Explorer_GetSelected" script @mikeyww was referring to, you can do something like this:

Code: Select all

^+z::                                                      ; ctrl-shift z
arr := strsplit(Explorer_GetSelected(),"`n")
stmp := "zip" . A_Year . A_MM . A_DD "_" A_Hour . A_min . A_sec . ".zip"
InputBox, sZip, , , , 450, 150, , , , , % Explorer_GetPath() . "\" . stmp
if ErrorLevel
    return
Zip(arr,sZip)
return

Zip(FilesToZip,sZip)										; FilesToZip is an array
	{
	cnt := FilesToZip.count()
	Progress, p1 CWFFFFFF CT000000 b x750 y800 w390 FS9, % "Zipping file 1 of " cnt  		; I know, deprecated	
	If Not FileExist(sZip)
		CreateZipFile(sZip)
	psh := ComObjCreate("Shell.Application")
	pzip := psh.Namespace(sZip)
	for x,y in FilesToZip
		{
		pzip.CopyHere(y, 4|16)
		while (pzip.Items().count < x)
			sleep, 250
		Progress, % 100 * (x/cnt), % "Zipping file " pzip.Items().count + 1 . " of " . cnt   
		}
	Progress, 100, Done!
	sleep, 1000
	Progress, off
	}

CreateZipFile(sZip)
	{
	Header1 := "PK" . Chr(5) . Chr(6)
	VarSetCapacity(Header2, 18, 0)
	file := FileOpen(sZip,"w")
	file.Write(Header1)
	file.RawWrite(Header2,18)
	file.close()
	}

Explorer_GetPath(hwnd="")
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
		return A_Desktop
	path := window.LocationURL
	path := RegExReplace(path, "ftp://.*@","ftp://")
	StringReplace, path, path, file:///
	StringReplace, path, path, /, \, All 
	
	; thanks to polyethene
	Loop
		If RegExMatch(path, "i)(?<=%)[\da-f]{1,2}", hex)
			StringReplace, path, path, `%%hex%, % Chr("0x" . hex), All
		Else Break
	return path
}
Explorer_GetAll(hwnd="")
{
	return Explorer_Get(hwnd)
}
Explorer_GetSelected(hwnd="")
{
	return Explorer_Get(hwnd,true)
}

Explorer_GetWindow(hwnd="")
{
	; thanks to jethrow for some pointers here
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
	
	if (process!="explorer.exe")
		return
	if (class ~= "(Cabinet|Explore)WClass")
	{
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd==hwnd)
				return window
	}
	else if (class ~= "Progman|WorkerW") 
		return "desktop" ; desktop found
}
Explorer_Get(hwnd="",selection=false)
{
	if !(window := Explorer_GetWindow(hwnd))
		return ErrorLevel := "ERROR"
	if (window="desktop")
	{
		ControlGet, hwWindow, HWND,, SysListView321, ahk_class Progman
		if !hwWindow ; #D mode
			ControlGet, hwWindow, HWND,, SysListView321, A
		ControlGet, files, List, % ( selection ? "Selected":"") "Col1",,ahk_id %hwWindow%
		base := SubStr(A_Desktop,0,1)=="\" ? SubStr(A_Desktop,1,-1) : A_Desktop
		Loop, Parse, files, `n, `r
		{
			path := base "\" A_LoopField
			IfExist %path% ; ignore special icons like Computer (at least for now)
				ret .= path "`n"
		}
	}
	else
	{
		if selection
			collection := window.document.SelectedItems
		else
			collection := window.document.Folder.Items
		for item in collection
			ret .= item.path "`n"
	}
	return Trim(ret,"`n")
}
Thanks for this code, @flyingDman. I have three questions about it:

1. Is it possible to default the name of the created .zip file to the name of the current folder? Like, if the .zip file is to be created at C:\User\Documents\Project\, the input box would show as default text C:\User\Documents\Project\Project.zip.

2. Is it possible to skip the Inputbox that prompts you to name the file and have the .zip folder appear directly in the folder with the default name?

3. Is it possible to default to .rar instead of .zip?

EDIT: The script worked fine the first time I tried it, but now it creates the compressed file in the location the script itself is located, not in the same folder the files to be compressed are. The only thing I changed from the original code is the hotkey, to ^+f
UPDATE: found out this is due to the fact that I was using Windows 11's explorer tabs and the script was getting the path to the first tab only. Is there way to circumvent this?

User avatar
flyingDman
Posts: 2846
Joined: 29 Sep 2013, 19:01

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by flyingDman » 23 Jan 2023, 17:28

Could you test this?:

Code: Select all

^+z::                                                      			; ctrl-shift z
InputBox, sZip, , , , 450, 150, , , , , % GetPath() . "\" . strsplit(GetPath(),"\").pop() . ".zip"
if ErrorLevel
    return
Zip(GetSelected(),sZip)
return

Zip(FilesToZip,sZip,del=0)										; FilesToZip is an array
	{
	cnt := FilesToZip.count()
	Progress, p1 CWFFFFFF CT000000 b x750 y800 w390 FS9, % "Zipping file 1 of " cnt  		; I know, deprecated
	If Not FileExist(sZip)
		CreateZipFile(sZip)
	psh := ComObjCreate("Shell.Application")
	pzip := psh.Namespace(sZip)
	for x,y in FilesToZip
		{
		;~ pzip.CopyHere(y, 4|16)
		pzip.CopyHere(y, 1028)
		while (pzip.Items().count < x)
			sleep, 250
		Progress, % 100 * (x/cnt), % "Zipping file " pzip.Items().count + 1 . " of " . cnt
		if (del = 1)
			FileDelete, %y%
		}
	Progress, 100, Done!
	sleep, 1000
	Progress, off
	}

CreateZipFile(sZip)
	{
	Header1 := "PK" . Chr(5) . Chr(6)
	VarSetCapacity(Header2, 18, 0)
	file := FileOpen(sZip,"w")
	file.Write(Header1)
	file.RawWrite(Header2,18)
	file.close()
	}


GetSelected()				; returns an array of selected filenames
	{
	selection := []
	WinGetClass class, % "ahk_id " hwnd := WinExist("A")
	if (class ~= "(Cabinet|Explore)WClass")
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd==hwnd)
				for item in window.document.SelectedItems
					selection.Push(item.Path)
	return selection
	}

GetPath()					; returns the path of the selected files
	{
	selection := []
	WinGetClass class, % "ahk_id " hwnd := WinExist("A")
	if (class ~= "(Cabinet|Explore)WClass")
		for window in ComObjCreate("Shell.Application").Windows
			if (window.hwnd==hwnd)
				path := window.Document.Folder.Self.Path
	return path
	}
Without inputbox:

Code: Select all

^+z::                                                      			; ctrl-shift z
sZip := GetPath() . "\" . strsplit(GetPath(),"\").pop() . ".zip"
Zip(GetSelected(),sZip)
return
I'm am not aware of any method to do this with rar's...
14.3 & 1.3.7

Avastgard
Posts: 133
Joined: 30 Sep 2016, 21:54

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by Avastgard » 24 Jan 2023, 07:55

Thank you very much, it works perfectly, even when using Windows 11's multiple explorer tabs.

EDIT: Last request, I promise: would it be possible to split the .zip files into smaller .zip files so that each one does not exceed a certain size? In some occasions I have to upload a lot of files to platforms that do not accept files larger than a certain size. In some it's 3 MB, others 5 MB, etc. I'm thinking maybe a prompt that asks user for the max file size and then it splits the zip files accordingly.

User avatar
flyingDman
Posts: 2846
Joined: 29 Sep 2013, 19:01

Re: Create Send-To-Compressed (zipped)-folder event shortcut (or AutoHotKey Shortcut) on Windows 10

Post by flyingDman » 24 Jan 2023, 13:15

I don't think you can calculate the size of a .zip file before it is zipped. If you know the compression ratio of the files to be zipped, you can approximate it, but compression ratios vary and this is likely to highly inaccurate. Obviously, once created you can find out the exact size of the .zip file and have your script then delete the file and create multiple zip files instead of one. But that will at least double the time to create the .zip files.
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”