Method

FolderItem.Item


Warning

This item was deprecated in version 2019r2. Please use FolderItem.ChildAt as a replacement.

Description

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

Notes

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 macOS. To see how to delete the contents of a folder, see the example in FolderItem.Remove.

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.ChildAt, 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.

Sample code

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

Compatibility

All project types on all supported operating systems.