Delete files older than XXX days old
Hello,
I need some help completing an app. My VB5 project simply creates text files every day and stores them in a specific folder. I need to write a cleanup routine that will look into this folder and delete the text files that are older than X days old. How can I look in a folder to get all the files it contains and then get the date/time stamp from these files and delete them based on their date? PLEASE HELP !!! Reply directly to my email address if you can. [email protected]
Thank You,
Mark
Re: Delete files older than XXX days old
Hi
Try something like :
Dim sFileName As String
Dim dteFileDate As Date
sFileName = Dir("c:\temp\*.tmp")
Do While Len(sFileName) > 0
dteFileDate = FileDateTime("c:\temp\" & sFileName)
If dteFiledate < Now() Then ' Or whatever date you want
Kill "c:\temp\" & sFileName
End If
sFileName = Dir ' Get next entry.
Loop
You'll have to change the "c:\temp" and other paramters to match your own criteria, but it will work.
Regards
Chris Eastwood
Codeguru - the website for developers
http://www.codeguru.com/vb
Re: Delete files older than XXX days old