------------------------ Charles Yeomans http://www.declareSub.com/
On Feb 25, 2007, at 7:28 PM, Andy Dent wrote: > On 26/02/2007, at 1:18 AM, Charles Yeomans wrote: > >> for i as Integer = f.Count downTo 1 >> DeleteItem f.TrueItem(i) >> next > > Whilst the Count downto 1 idiom is faster for things like skimming > through arrays, in this case isn't it a bit unsafe if the size of the > directory changes through other means whilst you are deleting? Not in this case. If the number of elements in a directory changes during deletion, then it's possible that f.TrueItem will return nil. But this possibility is handled. The other possibility is that items are added to a directory. In this case, some items may not be deleted, and f.Delete will fail. And there are other things to consider. If some items cannot be deleted, then DeleteItem will ultimately fail. What should the behavior be in this situation. My code simply deletes everything that can be deleted. But it may be that what you would want would be for DeleteItem to halt as soon as it encounters a FolderItem that it cannot delete. > > How much slower is 1 to Count for directories? I don't know; I did not offer this code with speed in mind. It is a simple, clean method that could serve as a starting point for optimization. Charles Yeomans _______________________________________________ Unsubscribe or switch delivery mode: <http://www.realsoftware.com/support/listmanager/> Search the archives: <http://support.realsoftware.com/listarchives/lists.html>
