FolderItem.Item

From Xojo Documentation

Method

FolderItem.Item(Index as Integer) As FolderItem

Supported for all project types and targets.

If this FolderItem is a directory, Index is an element in a one-based array of FolderItems in this directory.

Notes

fa-info-circle-32.png
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 macOS. To see how to delete the contents of a folder, see the example in FolderItem.Delete.

Be aware that the returned FolderItem object may be nil, e.g. if current file permissions deny access to it.

Alias Resolution

If the FolderItem is an Alias, Item automatically resolves the Alias and returns a FolderItem for the original file, folder, or application.

If necessary, macOS will mount external volumes and may present a login dialog during alias resolution. Be aware that this can lead to network accesses when macOS tries to automatically resolve the Alias, with long timeouts before the Item function returns with an error when the destination is not reachable. Therefore, on macOS, in most cases, you rather should use FolderItem.TrueItem, then test the returned item's Alias property and only then consider resolving it later:

item = item.Parent.Child(item.Name)

and stop doing this if you encounter an error, giving the user a chance to gracefully exit any loops.

Performance Considerations

Avoid calling this function several times as it is costly in processing time. If you need to get several properties of an item, get it once and store it in a variable of type FolderItem, then access that variable instead.

Example

This example puts the names of all the items on the Desktop that are stored on the boot volume into ListBox1.

Dim itemIdx, dirCount As Integer
Dim dir, item As FolderItem
dir = SpecialFolder.Desktop
dirCount = dir.Count
For itemIdx = 1 To dirCount
item = dir.Item(itemIdx)
If item <> Nil Then
ListBox1.AddRow(item.Name)
End If
Next