FolderItem.Child

From Xojo Documentation

Method

FolderItem.Child(Name as String, followAlias as Boolean = True) As FolderItem

Supported for all project types and targets.

Returns a FolderItem that represents a file or folder/directory within this FolderItem with the matching name or index passed.

Notes

Shortcuts and aliases are resolved on all platforms.

Returns Nil only when some portion of the path to the child does not exist. For example:

SpecialFolder.System.Child("Yummy").Child("Cake")

will return Nil if:

  • SpecialFolder.System is nil or does not exist
  • the folder/directory "Yummy" does not exist

Raises UnsupportedFormatException if Name is blank.

Example

Var f, g As FolderItem
f = New FolderItem
g = FromSaveInfo(f.SaveInfo(Volume(0).Child("Documents"), 0))
If g <> Nil Then
Label2.Value = g.NativePath
Else
MessageBox("FolderItem does not exist!")
End If

Trying to access a path where several components of the path do not exist may cause a NilObjectException The following code will do this if :

  • the folder foo does not exist on the desktop
  • the folder bar does not exist inside folder foo
  • and the file somefile does not exist
Var f As FolderItem
f = SpecialFolder.Desktop.Child("foo").Child("bar").Child("somefile")

It does this because

  • SpecialFolder.Desktop works and returns a valid non-nil folderitem
  • SpecialFolder.Desktop.Child("foo") returns a valid but non-existing folder item (this would allow you to create items that do not exist)
  • SpecialFolder.Desktop.Child("foo").child("bar") returns nil
  • SpecialFolder.Desktop.Child("foo").child("bar").child("somefile") now tries to use a NIL item to access the file and this causes the NilObjectException