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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete *.trc files from a directory older than 1 hour using VB script

Status
Not open for further replies.

Prompting

Programmer
Aug 24, 2010
2
BH
Hi,
I need a VB script to delete only *.trc files from a directory which are older than 1 hour..

Help me out on this...

Thanks in Adv..
 
[tt][green]'your givens
sdir="c:\xyz"[/green]

dim dt, fso, odir, f
dt=now
set fso=createobject("scripting.filesystemobject")
if fso.folderexists(sdir) then
set odir=fso.getfolder(sdir)
for each f in odir.files
'"n" for minutes, "h" for hours etc
if (strcomp(fso.getextensionname(f.name),"trc",1)=0) and (datediff("n",f.datelastmodified,dt)>60) then
f.delete true 'forced
end if
next
set odir=nothing
else
wscript.echo "directory: " & sdir & " not found." & vbcrlf & "operation aborted."
end if
set fso=nothing
[/tt]
 
Thanks tsuji for the reply..
I have try this,
I schedule task the script using batchfile,
but the files still remains...
the trace files are with the name- "audittrace20100430123638_6552.trc"
can you please help me out becoz the files will created and the disk space is becoming low.

can u give example for deleting the doc files using the VB script..

Thanks in Adv..
Shiva


 
You can do away scheduler for testing, can you not?!
 
You mention you scheduled with a batch file. Just want to be sure you have saved the sample code as a text file with a VBS extension.

Also, no need to execute via a batch, you can run it directly from the scheduler using CSCRIPT.EXE "path to vbs.vbs"

I hope that helps.

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top