-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzipExtractFormat.ahk
104 lines (91 loc) · 2.63 KB
/
zipExtractFormat.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
; Define the hotkey to trigger the script (Ctrl + E)
^e::
selected_files:= StrSplit(getSelected1(),"`n"," `r`n")
Loop % selected_files.Length() {
selected_file := Trim(selected_files[A_Index])
Splitpath, selected_file, , fdir, , fnamene,
outuptFolder:= fdir . "/" . fnamene
;Send, #r
;Sleep, 300
;Send, {Enter}
;Sleep, 900
;Send, 7z x "%selected_file%" -o"%outuptFolder%"
if FileExist(outuptFolder)
FileRemoveDir, %outuptFolder%, 1
RunWait, 7z x "%selected_file%" -o"%outuptFolder%" ; Extracting Files
RunWait, format.bat "%outuptFolder%" ; Foramating Files
}
getSelected1() {
cO:=clipboardAll
clipboard:=
send ^c
clipWait
selected:=clipboard
clipboard:=cO
return selected
}
; Refresh the Explorer window to show the extracted files
IfWinActive, ahk_class CabinetWClass
{
WinGetClass, CabinetWClass, A
ControlSend, , {F5}, ahk_class %CabinetWClass%
}
; Clear the clipboard to prevent accidental pasting
Clipboard :=
Return
^+z::
;Get current working folder
Send, ^+n
Send, {Enter}
Send, ^+c
Send, {Delete}
Sleep, 500
path := clipboard
SplitPath, path, , dir
folderPathA := StrSplit(dir, "\") ;"
folderName := folderPathA[folderPathA.Length()]
dir := StrReplace(dir, """","")
folderPathA :=""
wordFolder := dir . "/" . "word"
pptxFolder := dir . "/" . "ppt"
xlsxFolder := dir . "/" . "xl"
extension := ""
;Getting the extension for zip file
if FileExist(wordFolder){
extension := ".docx"
}
if FileExist(pptxFolder){
extension := ".pptx"
}
if FileExist(xlsxFolder){
extension := ".xlsx"
}
if StrLen(extension) = 0 {
extension := ".zip"
}
toExclude := ""
outuptFolder := dir . "/" . folderName . "" . extension
temp := 1
;If there outuptFolder is already there, do not consider it for ziping and change outuptFolder name
while FileExist(outuptFolder){
toExclude := toExclude . "-xr`!" . """" . outuptFolder . """" . " "
outuptFolder :=dir . "/" . folderName . "v" . temp . "" . extension
temp := temp + 1
}
;Zip command
RunWait, 7z a -r "%outuptFolder%" "%dir%/*" %toExclude%
;Zip command
;Send, #r
;Sleep, 300
;Send, {Enter}
;Sleep, 900
;Send, 7z a -r "%dir%/%folderName%%extension%" "%dir%/_rels/" "%dir%/docProps/" "%dir%/%folder%/" "%dir%/[Content_Types].xml"
; Refresh the Explorer window to show the extracted files
IfWinActive, ahk_class CabinetWClass
{
WinGetClass, CabinetWClass, A
ControlSend, , {F5}, ahk_class %CabinetWClass%
}
; Clear the clipboard to prevent accidental pasting
Clipboard :=
Return