Unless a file cannot be deleted; then you have an infinite loop --
this might happen if f.Item(1) returns a directory. Or unless
f.Item(1) returns nil; then you get a NilObjectException. Here's one
way to do it reliably.
dim f as FolderItem = specialFolder.Temporary.child("ah")
dim items() as FolderItem
for i as Integer = 1 to f.Count
dim g as FolderItem = f.TrueItem(i)
if g <> nil then
items.Append g
end if
next
for each item as FolderItem in items
item.Delete
//don't bother checking LastErrorCode, because it's unreliable
next
Then you can check f.Count again, if you need to know whether
everything is gone.
Charles Yeomans
On Mar 31, 2009, at 2:28 PM, Kimball Larsen wrote:
Except that item() is a 1-based array, so you need to use item(1).
Oh, and I changed it to use a while loop instead of a for:
dim f as FolderItem = specialFolder.Temporary.child("ah")
dim f2 as folderItem
dim i as integer
while f.count > 0
f2 = f.item(1)
f2.Delete
wend
f.delete
Works fine now, thanks!
- Kimball
http://www.kimballlarsen.com
On Mar 31, 2009, at 12:15 PM, Andy Dent wrote:
On 01/04/2009, at 2:09 AM, Kimball Larsen wrote:
Has anyone noticed any problem with folderitem.delete where it
deletes some files, but not others?
Here's the background: I'm trying to empty a directory that I
created to hold some temporary images. Here is the code I'm using
to delete:
dim f as FolderItem = specialFolder.Temporary.child("ah")
dim f2 as folderItem
dim i as integer
for i = 1 to f.Count
f2 = f.item(i)
use item(0) here always, not item(i)
You want to delete f.Count files. As you delete them, the effect of
the item call changes.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|