Re: Zip and Unzip files and folders by MVS
MVS
Tue Jan 04 16:30:15 CST 2005
"Miyahn" <HQF03250@nifty.ne.jp> escribió en el mensaje
news:eX1BFMj8EHA.2192@TK2MSFTNGP14.phx.gbl...
> "MVS" wrote in message news:e2lgIRe8EHA.2156@TK2MSFTNGP10.phx.gbl
>> I have a script that makes a backup of my info, in win2003 server, but I
>> need zip and unzip my info with the same backup script, I dont want
>> install
>> software extra, I want use the way that windows have to make compressed
>> ziped folders.
>
> The following is an example to zip files or folders.(but is not so
> reliable.)
> Only tested on WinXP Home Japanese version.
>
> ' FileName : ZipMake.vbs
> Const ssfDesktop = 0, ssfDesktopDirectory = 16
> Dim Args, Arg, SA, Dst, Zip, ZipFolder, Src
> Set Args = WScript.Arguments
> If Args.Count < 1 Then ShowUsage: WScript.Quit
> Set SA = CreateObject("Shell.Application")
> Dst = SA.NameSpace(ssfDesktopDirectory).Items.Item.Path
> With CreateObject("Scripting.FileSystemObject")
> Zip = .BuildPath(Dst, .GetBaseName(Args(0)) & ".zip")
> .CreateTextFile(Zip, True).Write _
> Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
> Set ZipFolder = SA.NameSpace(Zip)
> For Each Arg In Args
> On Error Resume Next
> Set Src = SA.NameSpace(Arg)
> If Src Then
> ZipFolder.CopyHere Src.Items
> Else
> ZipFolder.CopyHere SA.NameSpace(ssfDesktop).ParseName(Arg)
> End If
> On Error GoTo 0
> Next
> End With
> CheckBusy
> Set Src = Nothing: Set ZipFolder = Nothing: Set SA = Nothing
> MsgBox "The process was completed."
> '
> Sub ShowUsage
> MsgBox "Drag & drop File or Folder icon(s)", , "ZipMake Usage"
> End Sub
> '
> Sub CheckBusy
> Dim Counter
> With
> GetObject("winmgmts:Win32_PerfFormattedData_PerfProc_Process.Name='wscript'")
> Do While Counter < 2
> .Refresh_: WScript.Sleep 1000
> If .PercentProcessorTime = 0 Then Counter = Counter + 1 Else Counter
> = 0
> Loop
> End With
> End Sub
>
> --
> Miyahn (Masataka Miyashita) JPN
> Microsoft MVP (Office Systems - Excel)
> HQF03250@nifty.ne.jp
>
Tanks Miyahn, but I am not so good.
I was trying understand your script to make my own script.
I just want to select some files and compress them in a zip file, with out
make so many validations in my script.
I was trying to modify your script but it doesnt work.
It have to make a works.zip file in C:\test, with *.txt files in C:\test
Here is:
strComputer = "mypc"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set SA = CreateObject("Shell.Application")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Extension = 'txt'")
With CreateObject("Scripting.FileSystemObject")
Zip = .BuildPath("c:\test\", "works.zip")
.CreateTextFile(Zip, True).Write _
Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
Set ZipFolder = SA.NameSpace(Zip)
For Each objFile in colFiles
ZipFolder.CopyHere SA.NameSpace(objFile.FileName _
& "." & objFile.Extension)
Next
End With
CheckBusy
Set ZipFolder = Nothing: Set SA = Nothing
MsgBox "The process was completed."
'
Sub ShowUsage
MsgBox "Drag & drop File or Folder icon(s)", , "ZipMake Usage"
End Sub
'
Sub CheckBusy
Dim Counter
With
GetObject("winmgmts:Win32_PerfFormattedData_PerfProc_Process.Name='wscript'")
Do While Counter < 2
.Refresh_: WScript.Sleep 1000
If .PercentProcessorTime = 0 Then Counter = Counter + 1 Else Counter =
0
Loop
End With
End Sub