Problem with Example DelEntireFolder, ChildAt, FolderItem.Count

I’m getting an outofBounds exception with the example code for DelEntireFolder found in FolderItem.Remove.

The Code:
For i As Integer = 1 To itemCount
Var f As FolderItem
f = theFolder.ChildAt(i)
If f <> Nil Then
If f.IsFolder Then
dirs.AddRow(f)
Else
files.AddRow(f)
End If
End If
Next

I think the problem is between theFolder.Count and theFolder.ChildAt

Count starts at 1 and theFolder.ChildAt which uses index so it starts at 0.
From the LR:

FolderItem.ChildAt(Index as Integer, followAlias as Boolean = true) As FolderItem

I also tracked the files being added to the files array and it missed the first file.

I am posting this because I am forever overlooking count and index. It would be nice to know I didn’t .
Did I finally see Count correctly?

ChildAt is the API 2.0 version and Count is the API 1.0 version; you’re right, the example is mixing them and API 1.0 was 1 based and API 2.0 is zero based (for this concern).

The example has to be rewritten.

1 Like