Click to See Complete Forum and Search --> : Delete files older than XXX days old


Mark Berkowicz
March 24th, 1999, 02:25 PM
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. mdberk@erols.com

Thank You,

Mark

Chris Eastwood
March 25th, 1999, 03:53 AM
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

Mark Berkowicz
March 25th, 1999, 08:56 AM
Thanks a million.