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

    How to delete older files automatically

    Hi ,
    I want to delete the files from a folder automatically when files count reaches 10 .When i save a 11th file it should delete the 1 st file(i.e . older file) so that the folder should always have only 10 files.
    How to do it??
    Thanks in advance.
    Lata.

  2. #2
    Join Date
    May 2006
    Posts
    203

    Re: How to delete older files automatically

    Before creating new file every time check how many files you have in the folder if it reaches 11 then take the first one based one LastWritten time and delete then you can rename the files.

  3. #3
    Join Date
    May 2005
    Location
    Ellesmera
    Posts
    427

    Re: How to delete older files automatically

    well you can get all the files on the folder first to check how many existing file there is

    string[] fname = System.IO.Directory.GetFiles(directoryname)
    and from there your can get each of the files attribute and check which one is the oldest and delete it using "File.Delete(fileName)"
    *** Con Tu Adios, Te Llevas, Mi Corazon***

    Traveling Encoder...

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