New topic: 

File delete based on creation date

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

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        mbrogdon          Post subject: File delete based on creation 
datePosted: Mon Feb 04, 2013 6:39 pm                         
Joined: Thu Jan 24, 2013 5:10 pm
Posts: 7                Just wondering if this would make sense for a piece of 
file purge code.

It should delete files where the creation date of the file is older than 7 days.

Thanks.

// 86400 seconds = 24 hours
theDateTotalSeconds = todayDate.TotalSeconds
numberSecondsForDelete = 86400 * 7

For fileCount = currentPurgeFolder.Count DownTo 1
  
  If theDateTotalSeconds >= 
currentPurgeFolder.Item(fileCount).CreationDate.TotalSeconds + 
numberSecondsForDelete then
  
  MsgBox "file would have been deleted."
  'currentPurgeFolder.Item(fileCount).Delete
  
  End If
  
Next
   
                             Top                ktekinay          Post subject: 
Re: File delete based on creation datePosted: Mon Feb 04, 2013 6:47 pm          
                       
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 423
Location: New York, NY                Wouldn't the modification date make more 
sense?

I'd expect this code to run slowly on a folder with lots of files. This might 
be better:
dim cnt as integer = currentPurgeFolder.Count
dim fileList() as FolderItem
for fileCount as integer = 1 to cnt
  fileList.Append currentPurgeFolder.Item( fileCount )
next

for fileCount = 0 to fileList.Ubound
  dim thisItem as FolderItem = fileList( fileCount )
  if theDateTotalSeconds >= thisItem.CreationDate. ...
      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                mbrogdon          Post subject: 
Re: File delete based on creation datePosted: Mon Feb 04, 2013 7:38 pm          
               
Joined: Thu Jan 24, 2013 5:10 pm
Posts: 7                Creation date vs modification date isn't really 
relevant in this case as the creation date and modification date will be the 
same for all of the files, but in general, yes, the routine should probably use 
modification date and I will change it as suggested.

Would your code be faster because it's faster to create and then parse an array 
than to parse a folder of files?

Just trying to understand.

Also, does the math appear to be correct?   
                             Top                ktekinay          Post subject: 
Re: File delete based on creation datePosted: Mon Feb 04, 2013 9:50 pm          
                       
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 423
Location: New York, NY                Yes, the math seems right. And this is 
from the LR under FolderItem.Item:
Quote:Important Note: If you want to iterate over the contents of a directory, 
make sure to always do this starting at index 1, then increasing the index up 
to the value of FolderItem.Count. Avoid iterating backwards (using a For...Next 
loop with DownTo or Step -1), because that can potentially become extremely 
slow with larger directories, especially on Mac OS X. To see how to delete the 
contents of a folder, see the example in FolderItem.Delete.

So my version should be faster because it would grab all the items first, in 
order as suggested, then deal with each directly.      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                mbrogdon          Post subject: 
Re: File delete based on creation datePosted: Tue Feb 05, 2013 12:58 am         
                
Joined: Thu Jan 24, 2013 5:10 pm
Posts: 7                Ahhh...I saw that entry in the LR, but didn't recall 
the example reference.


Thanks!   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 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