Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 19, 2018 12:15 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: File delete based on creation date
PostPosted: Mon Feb 04, 2013 6:39 pm 
Offline

Joined: Thu Jan 24, 2013 5:10 pm
Posts: 14
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

_________________
REAL Studio 2011 R1


Top
 Profile  
Reply with quote  
 Post subject: Re: File delete based on creation date
PostPosted: Mon Feb 04, 2013 6:47 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
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
 Profile  
Reply with quote  
 Post subject: Re: File delete based on creation date
PostPosted: Mon Feb 04, 2013 7:38 pm 
Offline

Joined: Thu Jan 24, 2013 5:10 pm
Posts: 14
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?

_________________
REAL Studio 2011 R1


Top
 Profile  
Reply with quote  
 Post subject: Re: File delete based on creation date
PostPosted: Mon Feb 04, 2013 9:50 pm 
Offline
User avatar

Joined: Mon Feb 05, 2007 5:21 pm
Posts: 600
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
 Profile  
Reply with quote  
 Post subject: Re: File delete based on creation date
PostPosted: Tue Feb 05, 2013 12:58 am 
Offline

Joined: Thu Jan 24, 2013 5:10 pm
Posts: 14
Ahhh...I saw that entry in the LR, but didn't recall the example reference.


Thanks!

_________________
REAL Studio 2011 R1


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group