PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.win.server.scripting > Windows Script that will Save Files to ZIP file
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Windows Script that will Save Files to ZIP file

Réponse
 
LinkBack Outils de la discussion
Vieux 11/09/2007, 04h54   #1
M P
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Windows Script that will Save Files to ZIP file

I have C:\Data\*.* and wanting to save it to zip file thru windows
script. Is this possible?

  Réponse avec citation
Vieux 11/09/2007, 14h23   #2
LJB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file


"M P" <mponteres@gmail.com> wrote in message
news:1189479273.999620.23430@d55g2000hsg.googlegro ups.com...
>I have C:\Data\*.* and wanting to save it to zip file thru windows
> script. Is this possible?
>


This item slightly modified should be able to do it.

http://groups.google.com/group/micro...c?dmode=source

I'm not sure you can copy all files in a folder at once. You may have to
loop through them.

I have modified the above somewhat.

Const MyZip = "C:\test.zip"
Const File1 = "C:\Data\test1.txt"
Const File2 = "C:\Data\test2.txt"

'-------------- create empty zip file ---------
CreateObject("Scripting.FileSystemObject") _
.CreateTextFile(MyZip, True) _
.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

'-------------- zip the files ------------------
With CreateObject("Shell.Application")
'add files
.NameSpace(MyZip).CopyHere File1
.NameSpace(MyZip).CopyHere File2
End With
wScript.Sleep 1000

LJB


  Réponse avec citation
Vieux 11/09/2007, 16h19   #3
McKirahan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

"M P" <mponteres@gmail.com> wrote in message
news:1189479273.999620.23430@d55g2000hsg.googlegro ups.com...
> I have C:\Data\*.* and wanting to save it to zip file thru windows
> script. Is this possible?


Here's the URL of a scriptable zip program: http://www.7-zip.org/


Will this ?

Option Explicit
'*
'* Declare Variables
'*
Const cVBS = "7z.vbs"
Const cEXE = "7z.exe"
Const cFOL = "C:\Data\*.*" '= path of files to zip
Const cBAT = "7z_.bat"
Const cZIP = "7z_.zip"
Const cTXT = "7z_.txt"
Const cLOG = "7z_.log"
'*
'* Declare Variables
'*
Dim strDIR
strDIR = WScript.ScriptFullName
strDIR = Left(strDIR,InStrRev(strDIR,"\"))
Dim intFIL
intFIL = 0
Dim strFIL
Dim strFOL
strFOL = Replace(cFOL,"*.*","")
'*
'* Declare Objects
'*
Dim objCTF
Dim objFIL
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objGFO
Dim objOTF
Dim objWSS
'*
'* Delete Files
'*
If objFSO.FileExists(strDIR & cTXT) Then
objFSO.DeleteFile(strDIR & cTXT)
End If
If objFSO.FileExists(strDIR & cBAT) Then
objFSO.DeleteFile(strDIR & cBAT)
End If
If objFSO.FileExists(strDIR & cLOG) Then
objFSO.DeleteFile(strDIR & cLOG)
End If
If objFSO.FileExists(strDIR & cZIP) Then
objFSO.DeleteFile(strDIR & cZIP)
End If
'*
'* Identify Files
'*
Set objOTF = objFSO.OpenTextFile(strDIR & cTXT,2,True)
Set objGFO = objFSO.GetFolder(strFOL)
Set objFIL = objGFO.Files
For Each strFIL in objFIL
objOTF.WriteLine(strFOL & strFIL.Name)
intFIL = intFIL + 1
Next
Set objFIL = Nothing
Set objGFO = Nothing
Set objOTF = Nothing
'*
'* Create Batch File
'*
Set objCTF = objFSO.CreateTextFile(strDIR & cBAT,true)
objCTF.WriteLine(cEXE & " a " & cZIP & " @" & cTXT & " >> " & cLOG)
objCTF.WriteLine(cEXE & " l " & cZIP & " >> " & cLOG)
Set objCTF = Nothing
'*
'* Run Batch File
'*
Set objWSS = CreateObject("WScript.Shell")
objWSS.Run "%comspec% /C " & cBAT,7,True
Set objWSS = Nothing
'*
'* Destroy Objects
'*
Set objFSO = Nothing
'*
'* Finish Message
'*
MsgBox intfil & " files zipped.",vbInformation,cVBS







  Réponse avec citation
Vieux 17/09/2007, 09h07   #4
M P
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

Have tried this one and found working on my requierement. Thanks a
lot.

Btw, another question, how about including subfolders on the zip file?
Is this possible on your provided script?

On Sep 11, 8:23 pm, "LJB" <.> wrote:
> "M P" <> wrote in message
>
> news:1189479273.999620.23430@d55g2000hsg.googlegro ups.com...
>
> >I have C:\Data\*.* and wanting to save it to zip file thru windows
> > script. Is this possible?

>
> This item slightly modified should be able to do it.
>
> http://groups.google.com/group/micro...ng.vbscript/ms...
>
> I'm not sure you can copy all files in a folder at once. You may have to
> loop through them.
>
> I have modified the above somewhat.
>
> Const MyZip = "C:\test.zip"
> Const File1 = "C:\Data\test1.txt"
> Const File2 = "C:\Data\test2.txt"
>
> '-------------- create empty zip file ---------
> CreateObject("Scripting.FileSystemObject") _
> .CreateTextFile(MyZip, True) _
> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>
> '-------------- zip the files ------------------
> With CreateObject("Shell.Application")
> 'add files
> .NameSpace(MyZip).CopyHere File1
> .NameSpace(MyZip).CopyHere File2
> End With
> wScript.Sleep 1000
>
> LJB



  Réponse avec citation
Vieux 17/09/2007, 09h09   #5
M P
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

Thanks for your response but the script is kinda complicated. I have
found the previous post which is much simpler.\

On Sep 11, 10:19 pm, "McKirahan" <N...@McKirahan.com> wrote:
> "M P" <mponte...@gmail.com> wrote in message
>
> news:1189479273.999620.23430@d55g2000hsg.googlegro ups.com...
>
> > I have C:\Data\*.* and wanting to save it to zip file thru windows
> > script. Is this possible?

>
> Here's the URL of a scriptable zip program: http://www.7-zip.org/
>
> Will this ?
>
> Option Explicit
> '*
> '* Declare Variables
> '*
> Const cVBS = "7z.vbs"
> Const cEXE = "7z.exe"
> Const cFOL = "C:\Data\*.*" '= path of files to zip
> Const cBAT = "7z_.bat"
> Const cZIP = "7z_.zip"
> Const cTXT = "7z_.txt"
> Const cLOG = "7z_.log"
> '*
> '* Declare Variables
> '*
> Dim strDIR
> strDIR = WScript.ScriptFullName
> strDIR = Left(strDIR,InStrRev(strDIR,"\"))
> Dim intFIL
> intFIL = 0
> Dim strFIL
> Dim strFOL
> strFOL = Replace(cFOL,"*.*","")
> '*
> '* Declare Objects
> '*
> Dim objCTF
> Dim objFIL
> Dim objFSO
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Dim objGFO
> Dim objOTF
> Dim objWSS
> '*
> '* Delete Files
> '*
> If objFSO.FileExists(strDIR & cTXT) Then
> objFSO.DeleteFile(strDIR & cTXT)
> End If
> If objFSO.FileExists(strDIR & cBAT) Then
> objFSO.DeleteFile(strDIR & cBAT)
> End If
> If objFSO.FileExists(strDIR & cLOG) Then
> objFSO.DeleteFile(strDIR & cLOG)
> End If
> If objFSO.FileExists(strDIR & cZIP) Then
> objFSO.DeleteFile(strDIR & cZIP)
> End If
> '*
> '* Identify Files
> '*
> Set objOTF = objFSO.OpenTextFile(strDIR & cTXT,2,True)
> Set objGFO = objFSO.GetFolder(strFOL)
> Set objFIL = objGFO.Files
> For Each strFIL in objFIL
> objOTF.WriteLine(strFOL & strFIL.Name)
> intFIL = intFIL + 1
> Next
> Set objFIL = Nothing
> Set objGFO = Nothing
> Set objOTF = Nothing
> '*
> '* Create Batch File
> '*
> Set objCTF = objFSO.CreateTextFile(strDIR & cBAT,true)
> objCTF.WriteLine(cEXE & " a " & cZIP & " @" & cTXT & " >> " & cLOG)
> objCTF.WriteLine(cEXE & " l " & cZIP & " >> " & cLOG)
> Set objCTF = Nothing
> '*
> '* Run Batch File
> '*
> Set objWSS = CreateObject("WScript.Shell")
> objWSS.Run "%comspec% /C " & cBAT,7,True
> Set objWSS = Nothing
> '*
> '* Destroy Objects
> '*
> Set objFSO = Nothing
> '*
> '* Finish Message
> '*
> MsgBox intfil & " files zipped.",vbInformation,cVBS



  Réponse avec citation
Vieux 17/09/2007, 14h47   #6
LJB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

It worked for me with a folder of a few small files but seemed to fail with
large files. I'm not sure why that would be.

LJB

"M P" <mponteres@gmail.com> wrote in message
news:1190012832.184304.147090@o80g2000hse.googlegr oups.com...
> Have tried this one and found working on my requierement. Thanks a
> lot.
>
> Btw, another question, how about including subfolders on the zip file?
> Is this possible on your provided script?
>
> On Sep 11, 8:23 pm, "LJB" <.> wrote:
>> "M P" <> wrote in message
>>
>> news:1189479273.999620.23430@d55g2000hsg.googlegro ups.com...
>>
>> >I have C:\Data\*.* and wanting to save it to zip file thru windows
>> > script. Is this possible?

>>
>> This item slightly modified should be able to do it.
>>
>> http://groups.google.com/group/micro...ng.vbscript/ms...
>>
>> I'm not sure you can copy all files in a folder at once. You may have to
>> loop through them.
>>
>> I have modified the above somewhat.
>>
>> Const MyZip = "C:\test.zip"
>> Const File1 = "C:\Data\test1.txt"
>> Const File2 = "C:\Data\test2.txt"
>>
>> '-------------- create empty zip file ---------
>> CreateObject("Scripting.FileSystemObject") _
>> .CreateTextFile(MyZip, True) _
>> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>>
>> '-------------- zip the files ------------------
>> With CreateObject("Shell.Application")
>> 'add files
>> .NameSpace(MyZip).CopyHere File1
>> .NameSpace(MyZip).CopyHere File2
>> End With
>> wScript.Sleep 1000
>>
>> LJB

>
>



  Réponse avec citation
Vieux 18/09/2007, 03h51   #7
M P
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

Have tried it prompt me with an error:

Object required: 'NameSpace(...)'
Code 800A01A8

my Files are:

sFile1 = "C:\Data1"
sFile2 = "C:\Data2"
sFile3 = "C:\Data3"

These are folders with subfolders and files. Hope you might .


On Sep 17, 8:47 pm, "LJB" <.> wrote:
> It worked for me with a folder of a few small files but seemed to fail with
> large files. I'm not sure why that would be.
>
> LJB
>
> "M P" <mponte...@gmail.com> wrote in message
>
> news:1190012832.184304.147090@o80g2000hse.googlegr oups.com...
>
> > Have tried this one and found working on my requierement. Thanks a
> > lot.

>
> > Btw, another question, how about including subfolders on the zip file?
> > Is this possible on your provided script?

>
> > On Sep 11, 8:23 pm, "LJB" <.> wrote:
> >> "M P" <> wrote in message

>
> >>news:1189479273.999620.23430@d55g2000hsg.googleg roups.com...

>
> >> >I have C:\Data\*.* and wanting to save it to zip file thru windows
> >> > script. Is this possible?

>
> >> This item slightly modified should be able to do it.

>
> >>http://groups.google.com/group/micro...ng.vbscript/ms...

>
> >> I'm not sure you can copy all files in a folder at once. You may have to
> >> loop through them.

>
> >> I have modified the above somewhat.

>
> >> Const MyZip = "C:\test.zip"
> >> Const File1 = "C:\Data\test1.txt"
> >> Const File2 = "C:\Data\test2.txt"

>
> >> '-------------- create empty zip file ---------
> >> CreateObject("Scripting.FileSystemObject") _
> >> .CreateTextFile(MyZip, True) _
> >> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

>
> >> '-------------- zip the files ------------------
> >> With CreateObject("Shell.Application")
> >> 'add files
> >> .NameSpace(MyZip).CopyHere File1
> >> .NameSpace(MyZip).CopyHere File2
> >> End With
> >> wScript.Sleep 1000

>
> >> LJB



  Réponse avec citation
Vieux 18/09/2007, 14h08   #8
LJB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

I tried something similar to the following. If C:\Data1 contained a few
small files it would work for me and I'd end up with all the files in one
..zip as I expected. If the files were large I'd end up with a valid zip file
only containing C:\Data2\test.txt and another odd named file without an
extension. Opening it in a text editor it would appear to be a zip file but
after adding the .zip extension it still would not open with WinZip. I don't
have any idea what might be wrong.

sFile1 = "C:\Data1"
sFile2 = "C:\Data2\test.txt"

"M P" <mponteres@gmail.com> wrote in message
news:1190080271.784162.274640@o80g2000hse.googlegr oups.com...
> Have tried it prompt me with an error:
>
> Object required: 'NameSpace(...)'
> Code 800A01A8
>
> my Files are:
>
> sFile1 = "C:\Data1"
> sFile2 = "C:\Data2"
> sFile3 = "C:\Data3"
>
> These are folders with subfolders and files. Hope you might .
>
>
> On Sep 17, 8:47 pm, "LJB" <.> wrote:
>> It worked for me with a folder of a few small files but seemed to fail
>> with
>> large files. I'm not sure why that would be.
>>
>> LJB
>>
>> "M P" <mponte...@gmail.com> wrote in message
>>
>> news:1190012832.184304.147090@o80g2000hse.googlegr oups.com...
>>
>> > Have tried this one and found working on my requierement. Thanks a
>> > lot.

>>
>> > Btw, another question, how about including subfolders on the zip file?
>> > Is this possible on your provided script?

>>
>> > On Sep 11, 8:23 pm, "LJB" <.> wrote:
>> >> "M P" <> wrote in message

>>
>> >>news:1189479273.999620.23430@d55g2000hsg.googleg roups.com...

>>
>> >> >I have C:\Data\*.* and wanting to save it to zip file thru windows
>> >> > script. Is this possible?

>>
>> >> This item slightly modified should be able to do it.

>>
>> >>http://groups.google.com/group/micro...ng.vbscript/ms...

>>
>> >> I'm not sure you can copy all files in a folder at once. You may have
>> >> to
>> >> loop through them.

>>
>> >> I have modified the above somewhat.

>>
>> >> Const MyZip = "C:\test.zip"
>> >> Const File1 = "C:\Data\test1.txt"
>> >> Const File2 = "C:\Data\test2.txt"

>>
>> >> '-------------- create empty zip file ---------
>> >> CreateObject("Scripting.FileSystemObject") _
>> >> .CreateTextFile(MyZip, True) _
>> >> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

>>
>> >> '-------------- zip the files ------------------
>> >> With CreateObject("Shell.Application")
>> >> 'add files
>> >> .NameSpace(MyZip).CopyHere File1
>> >> .NameSpace(MyZip).CopyHere File2
>> >> End With
>> >> wScript.Sleep 1000

>>
>> >> LJB

>
>



  Réponse avec citation
Vieux 18/09/2007, 14h16   #9
LJB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

I haven't tried it yet but here is a link to something that is supposed to
zip a folder. http://www.rondebruin.nl/windowsxpzip.htm#folder

"LJB" <.> wrote in message news:e2Rohye%23HHA.1168@TK2MSFTNGP02.phx.gbl...
>I tried something similar to the following. If C:\Data1 contained a few
>small files it would work for me and I'd end up with all the files in one
>.zip as I expected. If the files were large I'd end up with a valid zip
>file only containing C:\Data2\test.txt and another odd named file without
>an extension. Opening it in a text editor it would appear to be a zip file
>but after adding the .zip extension it still would not open with WinZip. I
>don't have any idea what might be wrong.
>
> sFile1 = "C:\Data1"
> sFile2 = "C:\Data2\test.txt"
>
> "M P" <mponteres@gmail.com> wrote in message
> news:1190080271.784162.274640@o80g2000hse.googlegr oups.com...
>> Have tried it prompt me with an error:
>>
>> Object required: 'NameSpace(...)'
>> Code 800A01A8
>>
>> my Files are:
>>
>> sFile1 = "C:\Data1"
>> sFile2 = "C:\Data2"
>> sFile3 = "C:\Data3"
>>
>> These are folders with subfolders and files. Hope you might .
>>
>>
>> On Sep 17, 8:47 pm, "LJB" <.> wrote:
>>> It worked for me with a folder of a few small files but seemed to fail
>>> with
>>> large files. I'm not sure why that would be.
>>>
>>> LJB
>>>
>>> "M P" <mponte...@gmail.com> wrote in message
>>>
>>> news:1190012832.184304.147090@o80g2000hse.googlegr oups.com...
>>>
>>> > Have tried this one and found working on my requierement. Thanks a
>>> > lot.
>>>
>>> > Btw, another question, how about including subfolders on the zip file?
>>> > Is this possible on your provided script?
>>>
>>> > On Sep 11, 8:23 pm, "LJB" <.> wrote:
>>> >> "M P" <> wrote in message
>>>
>>> >>news:1189479273.999620.23430@d55g2000hsg.googleg roups.com...
>>>
>>> >> >I have C:\Data\*.* and wanting to save it to zip file thru windows
>>> >> > script. Is this possible?
>>>
>>> >> This item slightly modified should be able to do it.
>>>
>>> >>http://groups.google.com/group/micro...ng.vbscript/ms...
>>>
>>> >> I'm not sure you can copy all files in a folder at once. You may have
>>> >> to
>>> >> loop through them.
>>>
>>> >> I have modified the above somewhat.
>>>
>>> >> Const MyZip = "C:\test.zip"
>>> >> Const File1 = "C:\Data\test1.txt"
>>> >> Const File2 = "C:\Data\test2.txt"
>>>
>>> >> '-------------- create empty zip file ---------
>>> >> CreateObject("Scripting.FileSystemObject") _
>>> >> .CreateTextFile(MyZip, True) _
>>> >> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>>>
>>> >> '-------------- zip the files ------------------
>>> >> With CreateObject("Shell.Application")
>>> >> 'add files
>>> >> .NameSpace(MyZip).CopyHere File1
>>> >> .NameSpace(MyZip).CopyHere File2
>>> >> End With
>>> >> wScript.Sleep 1000
>>>
>>> >> LJB

>>
>>

>
>



  Réponse avec citation
Vieux 18/09/2007, 15h12   #10
LJB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

Based on http://www.rondebruin.nl/windowsxpzip.htm#folder I got the
following to work. It will compress folders with sub-folders.

Option Explicit

Dim ZipFile, SrcFldrs, Fldr

Const FOF_CREATEPROGRESSDLG = &H0&

SrcFldrs = Array("C:\Data1", "C:\Data2", "C:\Data3")
ZipFile = "C:\Data.zip"

'Create empty Zip File
CreateObject("Scripting.FileSystemObject") _
.CreateTextFile(ZipFile, True) _
.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

With CreateObject("Shell.Application")

For each Fldr in SrcFldrs
'Copy the files to the compressed folder
.NameSpace(ZipFile).CopyHere .NameSpace(Fldr).Items, FOF_CREATEPROGRESSDLG

'Keep script waiting until Compressing is done
On Error Resume Next
Do Until .NameSpace(ZipFile).Items.Count = .NameSpace(Fldr).Items.Count
wScript.Sleep 1000
Loop
On Error GoTo 0
Next
End With


"LJB" <.> wrote in message news:OV0w12e%23HHA.1208@TK2MSFTNGP05.phx.gbl...
>I haven't tried it yet but here is a link to something that is supposed to
>zip a folder. http://www.rondebruin.nl/windowsxpzip.htm#folder
>
> "LJB" <.> wrote in message news:e2Rohye%23HHA.1168@TK2MSFTNGP02.phx.gbl...
>>I tried something similar to the following. If C:\Data1 contained a few
>>small files it would work for me and I'd end up with all the files in one
>>.zip as I expected. If the files were large I'd end up with a valid zip
>>file only containing C:\Data2\test.txt and another odd named file without
>>an extension. Opening it in a text editor it would appear to be a zip file
>>but after adding the .zip extension it still would not open with WinZip. I
>>don't have any idea what might be wrong.
>>
>> sFile1 = "C:\Data1"
>> sFile2 = "C:\Data2\test.txt"
>>
>> "M P" <mponteres@gmail.com> wrote in message
>> news:1190080271.784162.274640@o80g2000hse.googlegr oups.com...
>>> Have tried it prompt me with an error:
>>>
>>> Object required: 'NameSpace(...)'
>>> Code 800A01A8
>>>
>>> my Files are:
>>>
>>> sFile1 = "C:\Data1"
>>> sFile2 = "C:\Data2"
>>> sFile3 = "C:\Data3"
>>>
>>> These are folders with subfolders and files. Hope you might .
>>>
>>>
>>> On Sep 17, 8:47 pm, "LJB" <.> wrote:
>>>> It worked for me with a folder of a few small files but seemed to fail
>>>> with
>>>> large files. I'm not sure why that would be.
>>>>
>>>> LJB
>>>>
>>>> "M P" <mponte...@gmail.com> wrote in message
>>>>
>>>> news:1190012832.184304.147090@o80g2000hse.googlegr oups.com...
>>>>
>>>> > Have tried this one and found working on my requierement. Thanks a
>>>> > lot.
>>>>
>>>> > Btw, another question, how about including subfolders on the zip
>>>> > file?
>>>> > Is this possible on your provided script?
>>>>
>>>> > On Sep 11, 8:23 pm, "LJB" <.> wrote:
>>>> >> "M P" <> wrote in message
>>>>
>>>> >>news:1189479273.999620.23430@d55g2000hsg.googleg roups.com...
>>>>
>>>> >> >I have C:\Data\*.* and wanting to save it to zip file thru windows
>>>> >> > script. Is this possible?
>>>>
>>>> >> This item slightly modified should be able to do it.
>>>>
>>>> >>http://groups.google.com/group/micro...ng.vbscript/ms...
>>>>
>>>> >> I'm not sure you can copy all files in a folder at once. You may
>>>> >> have to
>>>> >> loop through them.
>>>>
>>>> >> I have modified the above somewhat.
>>>>
>>>> >> Const MyZip = "C:\test.zip"
>>>> >> Const File1 = "C:\Data\test1.txt"
>>>> >> Const File2 = "C:\Data\test2.txt"
>>>>
>>>> >> '-------------- create empty zip file ---------
>>>> >> CreateObject("Scripting.FileSystemObject") _
>>>> >> .CreateTextFile(MyZip, True) _
>>>> >> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>>>>
>>>> >> '-------------- zip the files ------------------
>>>> >> With CreateObject("Shell.Application")
>>>> >> 'add files
>>>> >> .NameSpace(MyZip).CopyHere File1
>>>> >> .NameSpace(MyZip).CopyHere File2
>>>> >> End With
>>>> >> wScript.Sleep 1000
>>>>
>>>> >> LJB
>>>
>>>

>>
>>

>
>



  Réponse avec citation
Vieux 18/09/2007, 15h41   #11
LJB
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

Sorry about the error in the previous version. Here is an improved
version...I think. I'm not quite sure it will correctly count and zip all
files in sub-folders yet.

Option Explicit

Dim ZipFile, SrcFldrs, Fldr, iFiles

Const FOF_CREATEPROGRESSDLG = &H0&

SrcFldrs = Array("C:\Data1", "C:\Data2", "C:\Data3")
ZipFile = "C:\Data.zip"

'Create empty Zip File
CreateObject("Scripting.FileSystemObject") _
.CreateTextFile(ZipFile, True) _
.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

iFiles = 0

With CreateObject("Shell.Application")

For each Fldr in SrcFldrs
'Copy the files to the compressed folder
.NameSpace(ZipFile).CopyHere .NameSpace(Fldr).Items, FOF_CREATEPROGRESSDLG

iFiles = iFiles + .NameSpace(Fldr).Items.Count

'Keep script waiting until Compressing is done
On Error Resume Next
Do Until .NameSpace(ZipFile).Items.Count = iFiles
wScript.Sleep 1000
Loop
On Error GoTo 0
Next
End With


"LJB" <.> wrote in message news:u4xsRWf%23HHA.5464@TK2MSFTNGP02.phx.gbl...
> Based on http://www.rondebruin.nl/windowsxpzip.htm#folder I got the
> following to work. It will compress folders with sub-folders.
>
> Option Explicit
>
> Dim ZipFile, SrcFldrs, Fldr
>
> Const FOF_CREATEPROGRESSDLG = &H0&
>
> SrcFldrs = Array("C:\Data1", "C:\Data2", "C:\Data3")
> ZipFile = "C:\Data.zip"
>
> 'Create empty Zip File
> CreateObject("Scripting.FileSystemObject") _
> .CreateTextFile(ZipFile, True) _
> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>
> With CreateObject("Shell.Application")
>
> For each Fldr in SrcFldrs
> 'Copy the files to the compressed folder
> .NameSpace(ZipFile).CopyHere .NameSpace(Fldr).Items,
> FOF_CREATEPROGRESSDLG
>
> 'Keep script waiting until Compressing is done
> On Error Resume Next
> Do Until .NameSpace(ZipFile).Items.Count = .NameSpace(Fldr).Items.Count
> wScript.Sleep 1000
> Loop
> On Error GoTo 0
> Next
> End With
>
>
> "LJB" <.> wrote in message news:OV0w12e%23HHA.1208@TK2MSFTNGP05.phx.gbl...
>>I haven't tried it yet but here is a link to something that is supposed to
>>zip a folder. http://www.rondebruin.nl/windowsxpzip.htm#folder
>>
>> "LJB" <.> wrote in message
>> news:e2Rohye%23HHA.1168@TK2MSFTNGP02.phx.gbl...
>>>I tried something similar to the following. If C:\Data1 contained a few
>>>small files it would work for me and I'd end up with all the files in one
>>>.zip as I expected. If the files were large I'd end up with a valid zip
>>>file only containing C:\Data2\test.txt and another odd named file without
>>>an extension. Opening it in a text editor it would appear to be a zip
>>>file but after adding the .zip extension it still would not open with
>>>WinZip. I don't have any idea what might be wrong.
>>>
>>> sFile1 = "C:\Data1"
>>> sFile2 = "C:\Data2\test.txt"
>>>
>>> "M P" <mponteres@gmail.com> wrote in message
>>> news:1190080271.784162.274640@o80g2000hse.googlegr oups.com...
>>>> Have tried it prompt me with an error:
>>>>
>>>> Object required: 'NameSpace(...)'
>>>> Code 800A01A8
>>>>
>>>> my Files are:
>>>>
>>>> sFile1 = "C:\Data1"
>>>> sFile2 = "C:\Data2"
>>>> sFile3 = "C:\Data3"
>>>>
>>>> These are folders with subfolders and files. Hope you might .
>>>>
>>>>
>>>> On Sep 17, 8:47 pm, "LJB" <.> wrote:
>>>>> It worked for me with a folder of a few small files but seemed to fail
>>>>> with
>>>>> large files. I'm not sure why that would be.
>>>>>
>>>>> LJB
>>>>>
>>>>> "M P" <mponte...@gmail.com> wrote in message
>>>>>
>>>>> news:1190012832.184304.147090@o80g2000hse.googlegr oups.com...
>>>>>
>>>>> > Have tried this one and found working on my requierement. Thanks a
>>>>> > lot.
>>>>>
>>>>> > Btw, another question, how about including subfolders on the zip
>>>>> > file?
>>>>> > Is this possible on your provided script?
>>>>>
>>>>> > On Sep 11, 8:23 pm, "LJB" <.> wrote:
>>>>> >> "M P" <> wrote in message
>>>>>
>>>>> >>news:1189479273.999620.23430@d55g2000hsg.googleg roups.com...
>>>>>
>>>>> >> >I have C:\Data\*.* and wanting to save it to zip file thru windows
>>>>> >> > script. Is this possible?
>>>>>
>>>>> >> This item slightly modified should be able to do it.
>>>>>
>>>>> >>http://groups.google.com/group/micro...ng.vbscript/ms...
>>>>>
>>>>> >> I'm not sure you can copy all files in a folder at once. You may
>>>>> >> have to
>>>>> >> loop through them.
>>>>>
>>>>> >> I have modified the above somewhat.
>>>>>
>>>>> >> Const MyZip = "C:\test.zip"
>>>>> >> Const File1 = "C:\Data\test1.txt"
>>>>> >> Const File2 = "C:\Data\test2.txt"
>>>>>
>>>>> >> '-------------- create empty zip file ---------
>>>>> >> CreateObject("Scripting.FileSystemObject") _
>>>>> >> .CreateTextFile(MyZip, True) _
>>>>> >> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>>>>>
>>>>> >> '-------------- zip the files ------------------
>>>>> >> With CreateObject("Shell.Application")
>>>>> >> 'add files
>>>>> >> .NameSpace(MyZip).CopyHere File1
>>>>> >> .NameSpace(MyZip).CopyHere File2
>>>>> >> End With
>>>>> >> wScript.Sleep 1000
>>>>>
>>>>> >> LJB
>>>>
>>>>
>>>
>>>

>>
>>

>
>



  Réponse avec citation
Vieux 22/09/2007, 09h17   #12
M P
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Windows Script that will Save Files to ZIP file

Have tried the script.The script gets the files on Data1, Data2 and
Data3 folders and saves them on Data.zip. Can we just copy all files
and folders on Data1 and other folders as-is to the zip file? When
extracting the zip file, you will still get the exact folder
structure. I appreciate your and hoping to solve this script.

On Sep 18, 9:41 pm, "LJB" <.> wrote:
> Sorry about the error in the previous version. Here is an improved
> version...I think. I'm not quite sure it will correctly count and zip all
> files in sub-folders yet.
>
> Option Explicit
>
> Dim ZipFile, SrcFldrs, Fldr, iFiles
>
> Const FOF_CREATEPROGRESSDLG = &H0&
>
> SrcFldrs = Array("C:\Data1", "C:\Data2", "C:\Data3")
> ZipFile = "C:\Data.zip"
>
> 'Create empty Zip File
> CreateObject("Scripting.FileSystemObject") _
> .CreateTextFile(ZipFile, True) _
> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)
>
> iFiles = 0
>
> With CreateObject("Shell.Application")
>
> For each Fldr in SrcFldrs
> 'Copy the files to the compressed folder
> .NameSpace(ZipFile).CopyHere .NameSpace(Fldr).Items, FOF_CREATEPROGRESSDLG
>
> iFiles = iFiles + .NameSpace(Fldr).Items.Count
>
> 'Keep script waiting until Compressing is done
> On Error Resume Next
> Do Until .NameSpace(ZipFile).Items.Count = iFiles
> wScript.Sleep 1000
> Loop
> On Error GoTo 0
> Next
> End With
>
> "LJB" <.> wrote in messagenews:u4xsRWf%23HHA.5464@TK2MSFTNGP02.phx.gb l...
> > Based onhttp://www.rondebruin.nl/windowsxpzip.htm#folderI got the
> > following to work. It will compress folders with sub-folders.

>
> > Option Explicit

>
> > Dim ZipFile, SrcFldrs, Fldr

>
> > Const FOF_CREATEPROGRESSDLG = &H0&

>
> > SrcFldrs = Array("C:\Data1", "C:\Data2", "C:\Data3")
> > ZipFile = "C:\Data.zip"

>
> > 'Create empty Zip File
> > CreateObject("Scripting.FileSystemObject") _
> > .CreateTextFile(ZipFile, True) _
> > .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

>
> > With CreateObject("Shell.Application")

>
> > For each Fldr in SrcFldrs
> > 'Copy the files to the compressed folder
> > .NameSpace(ZipFile).CopyHere .NameSpace(Fldr).Items,
> > FOF_CREATEPROGRESSDLG

>
> > 'Keep script waiting until Compressing is done
> > On Error Resume Next
> > Do Until .NameSpace(ZipFile).Items.Count = .NameSpace(Fldr).Items.Count
> > wScript.Sleep 1000
> > Loop
> > On Error GoTo 0
> > Next
> > End With

>
> > "LJB" <.> wrote in messagenews:OV0w12e%23HHA.1208@TK2MSFTNGP05.phx.gb l...
> >>I haven't tried it yet but here is a link to something that is supposed to
> >>zip a folder.http://www.rondebruin.nl/windowsxpzip.htm#folder

>
> >> "LJB" <.> wrote in message
> >>news:e2Rohye%23HHA.1168@TK2MSFTNGP02.phx.gbl.. .
> >>>I tried something similar to the following. If C:\Data1 contained a few
> >>>small files it would work for me and I'd end up with all the files in one
> >>>.zip as I expected. If the files were large I'd end up with a valid zip
> >>>file only containing C:\Data2\test.txt and another odd named file without
> >>>an extension. Opening it in a text editor it would appear to be a zip
> >>>file but after adding the .zip extension it still would not open with
> >>>WinZip. I don't have any idea what might be wrong.

>
> >>> sFile1 = "C:\Data1"
> >>> sFile2 = "C:\Data2\test.txt"

>
> >>> "M P" <mponte...@gmail.com> wrote in message
> >>>news:1190080271.784162.274640@o80g2000hse.googl egroups.com...
> >>>> Have tried it prompt me with an error:

>
> >>>> Object required: 'NameSpace(...)'
> >>>> Code 800A01A8

>
> >>>> my Files are:

>
> >>>> sFile1 = "C:\Data1"
> >>>> sFile2 = "C:\Data2"
> >>>> sFile3 = "C:\Data3"

>
> >>>> These are folders with subfolders and files. Hope you might .

>
> >>>> On Sep 17, 8:47 pm, "LJB" <.> wrote:
> >>>>> It worked for me with a folder of a few small files but seemed to fail
> >>>>> with
> >>>>> large files. I'm not sure why that would be.

>
> >>>>> LJB

>
> >>>>> "M P" <mponte...@gmail.com> wrote in message

>
> >>>>>news:1190012832.184304.147090@o80g2000hse.goo glegroups.com...

>
> >>>>> > Have tried this one and found working on my requierement. Thanks a
> >>>>> > lot.

>
> >>>>> > Btw, another question, how about including subfolders on the zip
> >>>>> > file?
> >>>>> > Is this possible on your provided script?

>
> >>>>> > On Sep 11, 8:23 pm, "LJB" <.> wrote:
> >>>>> >> "M P" <> wrote in message

>
> >>>>> >>news:1189479273.999620.23430@d55g2000hsg.googleg roups.com...

>
> >>>>> >> >I have C:\Data\*.* and wanting to save it to zip file thru windows
> >>>>> >> > script. Is this possible?

>
> >>>>> >> This item slightly modified should be able to do it.

>
> >>>>> >>http://groups.google.com/group/micro...ng.vbscript/ms...

>
> >>>>> >> I'm not sure you can copy all files in a folder at once. You may
> >>>>> >> have to
> >>>>> >> loop through them.

>
> >>>>> >> I have modified the above somewhat.

>
> >>>>> >> Const MyZip = "C:\test.zip"
> >>>>> >> Const File1 = "C:\Data\test1.txt"
> >>>>> >> Const File2 = "C:\Data\test2.txt"

>
> >>>>> >> '-------------- create empty zip file ---------
> >>>>> >> CreateObject("Scripting.FileSystemObject") _
> >>>>> >> .CreateTextFile(MyZip, True) _
> >>>>> >> .Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

>
> >>>>> >> '-------------- zip the files ------------------
> >>>>> >> With CreateObject("Shell.Application")
> >>>>> >> 'add files
> >>>>> >> .NameSpace(MyZip).CopyHere File1
> >>>>> >> .NameSpace(MyZip).CopyHere File2
> >>>>> >> End With
> >>>>> >> wScript.Sleep 1000

>
> >>>>> >> LJB



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h28.


Édité par : vBulletin® version 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,38257 seconds with 20 queries