How to count the files in a zip and judge that only one fold or a file or some files in it?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lyscop
Posts: 14
Joined: 18 Dec 2021, 20:26

How to count the files in a zip and judge that only one fold or a file or some files in it?

22 Dec 2021, 08:44

I use the following code to unzip a selected file by 7zip to the same name fold, and it works well.

1, I want to count the files in a zip, and judge that only one fold or a file or some files in it.

In order to unzip through one shortcut to a new fold with the same name of the file, even if there is already a fold in it.

There are three conditions in the file:
A, Only one file
a, Unzip to the current fold
b, If the file exists, then rename it by the name add(1)

B, Only one fold
a, Unzip to the current fold directly
b, If the fold exists, the new fold name add(1)

C, Some files may be with fold(s)
a, Unzip to the new fold with the zip file name
b, If the fold exists, the new fold name add(1)

https://github.com/tterb/AutoHotkey-Scripts/blob/master/7zip.ahk

Code: Select all

^+y::
temp = %clipboard%
;KeyWait, LButton, D
;send {LButton}
sleep,100
Send, {Ctrl Down}c{Ctrl Up}
sleep,200
file = %clipboard% ;get file address
clipboard = %temp% ;restore clipboard
outdir := getdir(file)
runwait, "C:\Program Files\7-Zip\7z.exe" x "%file%" -o"%outdir%" -y,,hide ;Unzip to the same path and add a new fold
TrayTip, ,7zip has finished extracting "%file%", 1, 16
return

getdir(input)
{
SplitPath, input,,parentdir,,filenoext
final = %parentdir%\%filenoext%
return final
} 
2, I use the following code to unzip all the zip files of the 'D:\files' fold to the current path, how to unzip the selected zip(s).

Code: Select all

q::
TempDir =D:\12
oShell := ComObjCreate("Shell.Application")
oDir := oShell.NameSpace(TempDir)

Loop %TempDir%\*.zip
{
oZip := oShell.NameSpace(A_LoopFileFullPath)

    if !(oZip && oDir)
    {
        MsgBox 16, AutoHotkey,failed: unzip error.
        Run %TempDir%
        ExitApp
    }
    oDir.CopyHere(oZip.Items, 4)
}
oShell := oDir := oZip := ""
return
User avatar
TLM
Posts: 1608
Joined: 01 Oct 2013, 07:52
Contact:

Re: How to count the files in a zip and judge that only one fold or a file or some files in it?

22 Dec 2021, 22:27

lyscop wrote:
22 Dec 2021, 08:44
1, I want to count the files in a zip, and judge that only one fold or a file or some files in it.
The Namespace() Method has the Items property. Using it, you can loop through the compressed files and find out info on their contents.
For instance:

Code: Select all

TempDir = D:\12
oShell	:= ComObjCreate("shell.application")
oDir 	:= oShell.NameSpace(TempDir)

q::
Loop %TempDir%\*.zip
{
	oZip := oShell.NameSpace(A_LoopFileFullPath)
	For Item in oZip.Items 			; Loop Through Each Zip 
	{
		msgbox 	% "Zip File: " 		oZip.Title
				. "`nItem Count: " 	oZip.Items.Count
				. "`nItem Type: " 	Item.Type
				. "`nItem Name: " 	Item.Name
				. "`nItem Size: " 	Item.Size
	}
}
return
htms
lyscop
Posts: 14
Joined: 18 Dec 2021, 20:26

Re: How to count the files in a zip and judge that only one fold or a file or some files in it?

22 Dec 2021, 22:45

TLM wrote:
22 Dec 2021, 22:27
Spoiler
Thank you for your kind reply, maybe I don't make the description clear.

I want this part of the code the second one can unzip all the selected files instead of defining a path.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 172 guests