Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vbscript to zip files in a folder

Status
Not open for further replies.

codesearcher

Technical User
Feb 23, 2009
7
US
Hi All,
I am looking for a vb script with following requirement:
It should compress the files in a folder with extension "xml" as a zip folder.(Any sub folders within the folder should not be considered)
So compressed folder should have the current date as its name.
I dont want any third parties to be used.
I am using windows 2000 Server and the script should work fine in this server

Any help is greatly appreciated!!!!!

 
What do you have so far?

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
You might be better off writing a script that calls the Winzip Command Line Support Add-on. Obviously you can setup the folder and Zip file names up as part of the script and define what files are to be zipped, but then use the Winzip addon to perform the actual zipping (the EXE is PKZIP.EXE but the addon has to be installed on your server to work)


--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Why go to that trouble when VBScript has native support for zipping?

Trying to get the OP to do a little investigating on their own, but here is a sample. thread329-1231429

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Well Mark, you've taught me something today :) I was unaware you could zip files up entirely using VBScript.

Thanks

--------------------------------------
"Insert funny comment in here!"
--------------------------------------
 
Has anyone actually tried using the zip file script that Mark has linked to above?
It appears that it will create the zip file and copy files into it, but I am wondering if doing so will actually compresses the files at all?
 
You can compress with vbscript/WMI

Code:
' This code compresses a folder and its contents using NTFS compression
' ---------------------------------------------------------------
' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0
' ---------------------------------------------------------------

' ------ SCRIPT CONFIGURATION ------
strComputer = "."
strFolder   = "<FolderPath>" ' e.g. d:\scripts
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set objFolder = objWMI.Get("Win32_Directory='" & strFolder & "'")
intRC = objFolder.Compress  ' To uncompress change this to objFolder.Uncompress
if intRC <> 0 then
   WScript.Echo "There was an error compressing the folder: " & intRC
else
   WScript.Echo "Folder compression successful"
end if

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
>I am wondering if doing so will actually compresses the files at all?
What would be the point otherwise? Windows zip files use the DEFLATE algorithm.

Note that Mark's second example, NTFS compression, is not the same as zipping a file

 
VB6 related FSO stuff in thread222-1302498

>I am using windows 2000 Server
would not work for me under VB6/ Windows 2000 WorkStation.
 
Hey guys thank you for all your posts.

I have another requirement like the folder structure would be as given below:
C:\Files-Parent Directory
it contains subfolders like
1001
1002
1003
1004
....
1999

each of this sub folders contain xml file namely
a_1001.xml
b_1001.xml
c_1001.xml

a_1002.xml
b_1002.xml
c_1002.xml

..........
a_1999.xml
b_1999.xml
c_1999.xml
respectively.....

The actual requirement is i need to zip the xml files individually as a.zip,b.zip and c.zip where in a.zip should contain all the xml files with a_1001.xml,a_1002.xml,......a_1999.xml and
b.zip should contain b_1001.xml,b_1002.xml,......b_1999.xml and c.zip should have c_1001.xml,c_1002.xml,......c_1999.xml


 
 http://www.tek-tips.com/submitpost.cfm?pid=329
I highly recommend 7zip command line interface, from vba you would just execute a system command to call it.

7zip is free and extremely powerful.

Simi
 
Should not be a problem to just bind to the folders as demonstrated above. Use objFolder.Subfolders to enumrate the individual folders, bind to them and create your zips.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hey thanks a lot guys. The script to working fine with objFolder.Subfolders option....
Perfect Mark!!!
Bingo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top