FolderItem.Child

From Xojo Documentation

Method

FolderItem.Child(Name as String) As FolderItem

Supported for all project types and targets.

Returns a FolderItem that represents a file or directory within this FolderItem with the name Name.

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 directory "Yummy" does not exist

Raises UnsupportedFormatException if Name is blank.

Example

Dim f, g As FolderItem
f = New FolderItem
g = f.GetRelative(f.GetSaveInfo(Volume(0).Child("Documents"), 0))
If g <> Nil Then
Label2.Text = g.NativePath
Else
MsgBox("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 directory foo does not exist on the desktop
  • the directory bar does not exist inside directory foo
  • and the file somefile does not exist
Dim 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