New topic: 

Deleting the oldest file in a directory

<http://forums.realsoftware.com/viewtopic.php?t=46703>

         Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic          Author  
Message        RonBower          Post subject: Deleting the oldest file in a 
directoryPosted: Fri Jan 25, 2013 7:35 pm                         
Joined: Wed Feb 01, 2012 3:06 pm
Posts: 47                This forum has been of tremendous help so I have come 
back for more advice.

In my application, I have a RealSQLDatabase and I want to keep a reasonable 
number of backups in case the user decides to back out something he has done or 
needs to try to recover from some type of error.

So far, I have written code that creates a copy of the database file every time 
the user commits records to the database. The routine seems to be working okay 
and the final part of the project will be to provide a user interface to open 
the contents of the backup folder and choose a file to use to recover data.

What I want to do next, however, is to start the deleting oldest backup file 
whenever I create a new one and exceed some preset limit.

Say, for example, that I set a limit of 50 backup files. So, after I create a 
backup file I then check how many files are in the backup folder.  If I find 
more than 50, then I want to delete the oldest backup file.

I've read some of the cautions in the Language Reference about some of the 
procedures being time consuming so want to request advice.

What would be an efficient way to find the oldest file in a directory and 
delete it ?

My current thought is to get the file count and then use the FolderItem.Item 
method on the folder to examine each file, save the creation date of each, and 
after going though all in the folder delete the oldest that I found.

Is there a smoother way to find and delete the oldest file in a directory ?

Ron Bower
Ellicott City, MD   
                             Top                Sky Stream          Post 
subject: Re: Deleting the oldest file in a directoryPosted: Fri Jan 25, 2013 
10:01 pm                         
Joined: Sun Nov 23, 2008 12:27 am
Posts: 373
Location: New Jersey                I written an application that does 
something similar to what you are looking to do.

In a nutshell:

1) perform a recursive scan through your directory and store the file absolute 
path , file date to a database table.
2) run a query against this table to figure out what items you can delete and 
output it out to a recordset.
3) loop through the recordset and delete the files.

I think for something like this.. let sql do the heavy lifting of helping you 
decide what can be deleted.

On another note.. that is a lot of overhead if you are planning to backup a 
database after every commit. you might be better off looking at incorporating 
change control in the db design.      
_________________
- Rich  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

rbforumnotifier@monkeybreadsoftware.de

Reply via email to