Winzip command prompt and conditionally deleting files in windows 2k/2k3

ant80

Senior member
Dec 4, 2001
411
0
0
Every month, we have to compress specific files from a particular folder and delete them. I am able to compress so far, but dont know how to delete. I am trying to delete files older than a particular date using windows scripting. Here's my code so far.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec(" ""C:\Program Files\WinZip\wzzip"" -ex -Tf04-04-15 ""D:\Logfiles\W3SVC1\2004-05-15.zip"" ""D:\Logfiles\W3SVC1\*.log""")


It gives me an error saying "The system cannot find the file specified". Code: 80070002. Source: WshShell.exec

In the dos prompt, I tried to run the following command: "C:\Program Files\WinZip\wzzip" -ex -Tf04-04-15 "D:\Logfiles\W3SVC1\2004-05-15.zip" "D:\Logfiles\W3SVC1\*.log" and it ran perfectly. I checked the zip file created and it was good. Is there a reason the file doesn't work when it is run as a vbs script?

Next, i tried to incorporate -d in the command line to delete the files that have been compressed. However, I got an error saying -d and -T cannot be combined in the same command. So my next question is, how can I delete the files that are older than a particular date? Note that all files are .log files.

Any help would be appreciated. Thanks.
- Ananth
 
 

KB

Diamond Member
Nov 8, 1999
5,406
389
126
Instead of using the Exec method you might try the Run method as it is more predictable

ReturnCode = WshShell.Run(" ""C:\Program Files\WinZip\wzzip.exe"" -ex -Tf04-04-15 ""D:\Logfiles\W3SVC1\2004-05-15.zip"" ""D:\Logfiles\W3SVC1\*.log""", 0, true)

Also include the .exe at the end of the path for wzzip.exe.

You can use vbscript delete older files. Here is a sample.
 

ant80

Senior member
Dec 4, 2001
411
0
0
Thanks for the code KB. I tried the run command on one of the servers. And it worked!!!

I haven't tried the code to delete the stuff yet. I'll try it this Friday when I am scheduled to perform that task. I'll post the scenario when its done.

Two more questions for you. One, is it possible to clear event logs using the same tools? Or do I need perl to do that?

And two, could u suggest a good resource where I might be able to find answers to questions like these? A good online resource, or maybe even a book perhaps? Thanks.
- Ananth
 

ant80

Senior member
Dec 4, 2001
411
0
0
I tried to run it Friday, but the server didn't have winzip command line installed. So I had to wait until today...

And it worked. Thanks for the script KB. Really helped me out.
 

ant80

Senior member
Dec 4, 2001
411
0
0
Can anyone help me out here please? Here's my code.


Dim EventLog1 As New System.Diagnostics.EventLog()

EventLog1 As New EventLog("Application", "80855281U")

EventLog1.Clear ("C:\applicationLog.evt")


I am trying to backup and clear the Application eventlog. The code is actually from the Microsoft MSDN page. Unfortunately, I get an error message.

Line: 1
Char: 15
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error


Is there any way to make this run? Or do I need to install something in order to run this?