CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 1999
    Posts
    3

    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



  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    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

  3. #3
    Join Date
    Mar 1999
    Posts
    3

    Re: Delete files older than XXX days old



    Thanks a million.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured