1.

Solve : Batch File Syntax?

Answer»

I need to get a batch file that will search a directory and zip or delete files older than 30 days. Does anyone know where I can get ONE to tweak instead of trying to write it from scratch.Unless you are prepared to write a long series of IF statements to account for different length months and leap years, DOS batch does not do date calculations.

WinScript however, has many date functions. What version of Windows are you using?

I'm actually using a Netware 6.0 file server. Our WebTrends application starts to CHOKE if we get more than 30 days worth of logs for it to parse. I'm open to ideas. Thanks.XP on my workstationDoes XP have cal? (Like Unix)
If not you have to make a calender which is not trivial.

You can do maths with, for example, set /a yesterd=11-1
(If it is working like NT).

good luck
uliGenerally I dislike showing posters how to delete files. This little script will simply list the files in a given directory that WOULD be deleted.

Code: [Select]
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("drive:\FolderSpec")
Set fc = f.Files

For Each fs in fc
If fs.DateLastModified < Date - 30 Then
WScript.Echo fs.name & " " & fs.DateLastModified
End If
Next


Save the script with a vbs extension, change drive:\folderspec with a valid directory, and run it as CSCRIPT scriptname.vbs from the command line. Once you are satisfied everything is cool, replace the entire line starting with WScript.Echo with
fso.DeleteFile fs, True.

Note: Files deleted with batch files and scripts do not make the usual pitstop in the RECYCLE bin. They go straight to dataland.

Hope this helps. Thank you all very much. This is perfect.



Discussion

No Comment Found