-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathFilePreparerZip.vbs
More file actions
192 lines (177 loc) · 4.69 KB
/
FilePreparerZip.vbs
File metadata and controls
192 lines (177 loc) · 4.69 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
' ZIP.VBS manipulates ZIP file in command line.
' Usage: CScript.exe ZIP.VBS [-d|-e|-v] ZIPfile [files...]
' CScript.exe ZIP.VBS -a archive.zip 1.txt
Option Explicit
Dim arg
Dim optind
If WScript.Arguments.Count<1 Then
WScript.Echo "Usage: CScript.exe ZIP.VBS [-d|-e|-v] ZIPfile [files...]"
WScript.Quit
End If
arg=WScript.Arguments(optind)
Select Case LCase(arg)
Case "-a","-c"
optind=optind+1
Call MakeZIP()
Case "-d"
optind=optind+1
Call DeleteZIP()
Case "-e"
optind=optind+1
Call ExtractZIP()
Case "-v","-l"
optind=optind+1
Call ListZIP()
Case Else
If optind=WScript.Arguments.Count-1 Then
Call ListZIP()
Else
Call MakeZIP()
End If
End Select
WScript.Quit
Sub MakeZIP()
Dim fso
Dim wShell
Dim Shell
Dim n
Dim ie
Dim ZIPfile
Dim ZIPdata:ZIPdata="PK" & Chr(5) & Chr(6) & String(18,0)
Dim file
Dim Folder
Dim FolderItem
Dim dFolder
Dim fCount
If WScript.Arguments.Count<optind+2 Then
WScript.Echo "Arguments Missing."
WScript.Quit
End If
Set fso=CreateObject("Scripting.FileSystemObject")
Set wShell=CreateObject("WScript.Shell")
Set Shell=CreateObject("Shell.Application")
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind))
If UCase(fso.GetExtensionName(ZIPfile))<>"ZIP" Then
WScript.Echo "Invalid Extension Name -",fso.GetExtensionName(ZIPfile)
WScript.Quit
End If
If Not fso.FileExists(ZIPfile) Then
fso.CreateTextFile(ZIPfile,False).Write ZIPdata
End If
Set dFolder=Shell.NameSpace(ZIPfile)
fCount = 0
For optind=optind+1 To WScript.Arguments.Count-1
file=fso.GetAbsolutePathName(WScript.Arguments(optind))
Set Folder=Shell.NameSpace(fso.GetParentFolderName(file))
Set FolderItem=Folder.ParseName(fso.GetFileName(file))
If FolderItem Is Nothing Then
WScript.Echo WScript.Arguments(optind),"- Not Found."
WScript.Quit
End If
dFolder.CopyHere FolderItem, 4+16+2048
fCount = fCount+1
Do While dFolder.Items.Count < fCount
Wscript.Sleep(10)
Loop
Next
End Sub
Sub ListZIP()
Dim fso
Dim Shell
Dim ZIPfile
Dim Folder
Dim FolderItem
Dim k
Dim COL:COL=8
Dim cols
ReDim cols(COL)
Dim rows
Dim j
If WScript.Arguments.Count<optind+1 Then
WScript.Echo "Arguments Missing."
WScript.Quit
End If
Set fso=CreateObject("Scripting.FileSystemObject")
Set Shell=CreateObject("Shell.Application")
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind))
If UCase(fso.GetExtensionName(ZIPfile))<>"ZIP" Then
WScript.Echo "Invalid Extension Name -",fso.GetExtensionName(ZIPfile)
WScript.Quit
End If
Set Folder=Shell.NameSpace(ZIPfile)
ReDim rows(Folder.Items.Count)
For k=0 To COL
cols(k)=Folder.GetDetailsOf(,k)
Next
j=0
rows(j)=Join(cols,vbTab)
For Each FolderItem In Folder.Items
For k=0 To COL
Cols(k)=Folder.GetDetailsOf(FolderItem,k)
Next
j=j+1
rows(j)=Join(cols,vbTab)
Next
WScript.Echo Join(rows,vbCRLF)
End Sub
Sub DeleteZIP()
Dim fso
Dim Shell
Dim ZIPfile
Dim Folder
Dim FolderItem
If WScript.Arguments.Count<optind+2 Then
WScript.Echo "Arguments Missing."
WScript.Quit
End If
Set fso=CreateObject("Scripting.FileSystemObject")
Set Shell=CreateObject("Shell.Application")
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind))
If UCase(fso.GetExtensionName(ZIPfile))<>"ZIP" Then
WScript.Echo "Invalid Extension Name -",fso.GetExtensionName(ZIPfile)
WScript.Quit
End If
Set Folder=Shell.NameSpace(ZIPfile)
For optind=optind+1 To WScript.Arguments.Count-1
Set FolderItem=Folder.ParseName(WScript.Arguments(optind))
If FolderItem Is Nothing Then
WScript.Echo WScript.Arguments(optind),"- Not Found."
WScript.Quit
End If
' FolderItem.InvokeVerb("delete")
FolderItem.InvokeVerb("??(&D)")
Next
End Sub
Sub ExtractZIP()
Dim fso
Dim Shell
Dim ZIPfile
Dim Folder
Dim FolderItem
Dim dFolder
If WScript.Arguments.Count<optind+1 Then
WScript.Echo "Arguments Missing."
WScript.Quit
End If
Set fso=CreateObject("Scripting.FileSystemObject")
Set Shell=CreateObject("Shell.Application")
ZIPfile=fso.GetAbsolutePathName(WScript.Arguments(optind))
If UCase(fso.GetExtensionName(ZIPfile))<>"ZIP" Then
WScript.Echo "Invalid Extension Name -",fso.GetExtensionName(ZIPfile)
WScript.Quit
End If
Set Folder=Shell.NameSpace(ZIPfile)
Set dFolder=Shell.NameSpace(fso.GetAbsolutePathName(""))
If WScript.Arguments.Count<optind+2 Then
dFolder.CopyHere Folder.Items
Else
For optind=optind+1 To WScript.Arguments.Count-1
Set FolderItem=Folder.ParseName(WScript.Arguments(optind))
If FolderItem Is Nothing Then
WScript.Echo WScript.Arguments(optind),"- Not Found."
WScript.Quit
End If
dFolder.CopyHere FolderItem
Next
End If
End Sub