-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnZip.ahk
79 lines (68 loc) · 2.21 KB
/
UnZip.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;UnZip("C:\Users\PONDX\1.zip", "C:\Users\PONDX\Test")
SmartZip("C:\Users\PONDX\1.zip", "C:\Users\PONDX\Test") ; Unpack a number of ZIP files to dir2
;; --------- THE FUNCTION ------------------------------------
/*
SmartZip()
Smart ZIP/UnZIP files
Parameters:
s, o When compressing, s is the dir/files of the source and o is ZIP filename of object. When unpressing, they are the reverse.
t The options used by CopyHere method. For availble values, please refer to: http://msdn.microsoft.com/en-us/library/windows/desktop/bb787866
Link:
http://www.autohotkey.com/forum/viewtopic.php?p=523649#523649
*/
SmartZip(s, o, t = 4)
{
IfNotExist, %s%
return, -1 ; The souce is not exist. There may be misspelling.
oShell := ComObjCreate("Shell.Application")
if (SubStr(o, -3) = ".zip") ; Zip
{
IfNotExist, %o% ; Create the object ZIP file if it's not exist.
CreateZip(o)
Loop, %o%, 1
sObjectLongName := A_LoopFileLongPath
oObject := oShell.NameSpace(sObjectLongName)
Loop, %s%, 1
{
if (sObjectLongName = A_LoopFileLongPath)
{
continue
}
ToolTip, Zipping %A_LoopFileName% ..
oObject.CopyHere(A_LoopFileLongPath, t)
SplitPath, A_LoopFileLongPath, OutFileName
Loop
{
oObject := "", oObject := oShell.NameSpace(sObjectLongName) ; This doesn't affect the copyhere above.
if oObject.ParseName(OutFileName)
break
}
}
ToolTip
}
else if InStr(FileExist(o), "D") or (!FileExist(o) and (SubStr(s, -3) = ".zip")) ; Unzip
{
if !o
o := A_ScriptDir ; Use the working dir instead if the object is null.
else IfNotExist, %o%
FileCreateDir, %o%
Loop, %o%, 1
sObjectLongName := A_LoopFileLongPath
oObject := oShell.NameSpace(sObjectLongName)
Loop, %s%, 1
{
oSource := oShell.NameSpace(A_LoopFileLongPath)
oObject.CopyHere(oSource.Items, 0x14)
}
}
}
CreateZip(n) ; Create empty Zip file
{
ZIPHeader1 := "PK" . Chr(5) . Chr(6)
VarSetCapacity(ZIPHeader2, 18, 0)
ZIPFile := FileOpen(n, "w")
ZIPFile.Write(ZIPHeader1)
ZIPFile.RawWrite(ZIPHeader2, 18)
ZIPFile.close()
}
;; --------- FUNCTION END ------------------------------------