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

deleting files in batch script

Status
Not open for further replies.

langford

Technical User
Aug 25, 2001
13
0
0
GB
Does anyone know how I can delete files from a directory given that I wish to always keep the latest 3 files created?!?!
 
You can create a vbscript that will do this and activate it as a scheduled task on a pc that is running whenever this action is performed. If you need more source code goto microsoft website, the ya have a lot o f good resources. Something like this:

'************************************************************************
' This function returns the difference
' between the date modified and the present time.
'************************************************************************
Function GetTimeDiff(TimeModified, IsNow)

Dim Thediff

TimeModified = Trim(TimeModified)
IsNow = Trim(IsNow)
Thediff = DateDiff ("n", CDate(TimeModified),CDate(IsNow))
GetTimeDiff = CStr(Thediff)

End Function

StrTimeDiff = GetTimeDiff(TimeModified,IsNow)
'Timemodified is the '.datelastmodified' property returned


q
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top