Hi,

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.

Someone can help me???

Re: Zip and Unzip files and folders by Miyahn

Miyahn
Tue Jan 04 01:59:11 CST 2005

"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


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



Re: Zip and Unzip files and folders by Miyahn

Miyahn
Tue Jan 04 21:17:08 CST 2005

"MVS" wrote in message news:#w#Roxq8EHA.2900@TK2MSFTNGP09.phx.gbl

> 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'")

This query should be,
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\Test\\' " & _
"And 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)

Since NameSpace method only return a folder object, this line should be
ZipFolder.CopyHere SA.NameSpace(0).ParseName(objFile.Name)

--
Miyahn (Masataka Miyashita) JPN
Microsoft MVP (Office Systems - Excel)
HQF03250@nifty.ne.jp


Re: Zip and Unzip files and folders by MVS

MVS
Wed Jan 05 17:22:35 CST 2005

It work's!!!!!!!
Tank you so much Miyahn!!!!

I only have another doubt, it´s not important, but if you have time I'll
appreciate your help.

what happens if a have another hard disk and I have two folders with
different path and same name?, can I use in the query Path = '\\M:\Test\\'??
or how can I be more especific with the folders?
I use for copy files:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "C:\TEST\*.txt" , "D:\OK\TEST\" , TRUE
The point is: What happens if I am working with two or more hard disk drives
and if I want include a folder in works.zip.



"Miyahn" <HQF03250@nifty.ne.jp> escribio en el mensaje
news:%23ML08Rt8EHA.808@TK2MSFTNGP10.phx.gbl...
> "MVS" wrote in message news:#w#Roxq8EHA.2900@TK2MSFTNGP09.phx.gbl
>
>> 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'")
>
> This query should be,
> Set colFiles = objWMIService. _
> ExecQuery("Select * from CIM_DataFile where Path = '\\Test\\' " & _
> "And 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)
>
> Since NameSpace method only return a folder object, this line should be
> ZipFolder.CopyHere SA.NameSpace(0).ParseName(objFile.Name)
>
> --
> Miyahn (Masataka Miyashita) JPN
> Microsoft MVP (Office Systems - Excel)
> HQF03250@nifty.ne.jp
>



Re: Zip and Unzip files and folders by Miyahn

Miyahn
Thu Jan 06 04:31:38 CST 2005

"MVS" wrote in message news:uqOzVz38EHA.3820@TK2MSFTNGP11.phx.gbl
> I use for copy files:
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> objFSO.CopyFile "C:\TEST\*.txt" , "D:\OK\TEST\" , TRUE
> The point is: What happens if I am working with two or more hard disk drives
> and if I want include a folder in works.zip.

Well, try this.

Const SrcPath = "C:\TEST", strFilter1 = "*.txt", strFilter2 = "*"
Const DstPath = "D:\OK\TEST\works.zip"
Const SHCONTF_FOLDERS = &H20, SHCONTF_NONFOLDERS = &H40
Const SHCONTF_INCLUDEHIDDEN = &H80
Set SA = CreateObject("Shell.Application")
With CreateObject("Scripting.FileSystemObject")
.CreateTextFile(DstPath, True).Write _
Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
Set Src = SA.NameSpace(SrcPath).Items
' Copy all text files
Src.Filter SHCONTF_NONFOLDERS, strFilter1
SA.NameSpace(DstPath).CopyHere Src
' Copy all subfolders
Src.Filter SHCONTF_FOLDERS, strFilter2
SA.NameSpace(DstPath).CopyHere Src
End With
CheckBusy
Set Src = Nothing: Set SA = Nothing
' My favorite magic words to bring MsgBox in front of screen.
CreateObject("WScript.Shell").SendKeys "{F10}{ESC}", True
MsgBox "The process was completed."
'
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


Re: Zip and Unzip files and folders by MVS

MVS
Thu Jan 13 10:25:41 CST 2005

Tank you so much!!!
Doomo Arigato Gozaimasu
Anata wa ???------I try to say you: You are nice!!!

"Miyahn" <HQF03250@nifty.ne.jp> escribió en el mensaje
news:eLi%23pp98EHA.2196@TK2MSFTNGP11.phx.gbl...
> "MVS" wrote in message news:uqOzVz38EHA.3820@TK2MSFTNGP11.phx.gbl
>> I use for copy files:
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> objFSO.CopyFile "C:\TEST\*.txt" , "D:\OK\TEST\" , TRUE
>> The point is: What happens if I am working with two or more hard disk
>> drives
>> and if I want include a folder in works.zip.
>
> Well, try this.
>
> Const SrcPath = "C:\TEST", strFilter1 = "*.txt", strFilter2 = "*"
> Const DstPath = "D:\OK\TEST\works.zip"
> Const SHCONTF_FOLDERS = &H20, SHCONTF_NONFOLDERS = &H40
> Const SHCONTF_INCLUDEHIDDEN = &H80
> Set SA = CreateObject("Shell.Application")
> With CreateObject("Scripting.FileSystemObject")
> .CreateTextFile(DstPath, True).Write _
> Chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18, Chr(0))
> Set Src = SA.NameSpace(SrcPath).Items
> ' Copy all text files
> Src.Filter SHCONTF_NONFOLDERS, strFilter1
> SA.NameSpace(DstPath).CopyHere Src
> ' Copy all subfolders
> Src.Filter SHCONTF_FOLDERS, strFilter2
> SA.NameSpace(DstPath).CopyHere Src
> End With
> CheckBusy
> Set Src = Nothing: Set SA = Nothing
> ' My favorite magic words to bring MsgBox in front of screen.
> CreateObject("WScript.Shell").SendKeys "{F10}{ESC}", True
> MsgBox "The process was completed."
> '
> 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
>