GetFolderItem

From Real Software Documentation

Jump to: navigation, search
Method

Used to access an item in a folder (directory).

Syntax

result=GetFolderItem(path [,pathMode])

Part Type Description
result FolderItem Represents the file that was opened.
path String The path or an empty string.

Path is the name of a document if it is in the current directory. Otherwise, it can be one of three types of paths to other locations. See the optional pathMode parameter.

pathMode
Introduced 5.5
Class Constant The type of path that is passed.

It uses a FolderItem class constant. The following class constants can be passed:

Class Constant Value
PathTypeAbsolute 0
PathTypeShell 1
PathTypeURL 2

Use the class constants, not the numeric values in your code. The numeric values are provided for your information only and the values associated with the constants may change in subsequent versions of Real Studio. The pathtype parameter indicates whether the path is a Shell path, an “ordinary” path, or path in the form of a URL.

For example, to specify a Shell path, use the expression

FolderItem.PathTypeShell

If you pass a Shell path, it must be an absolute path. If not, an UnsupportedFormatException will result. See the ShellPath property of the FolderItem class for information about shell paths. If you pass FolderItem.PathTypeURL, it must begin with "file:///".

Notes

The GetFolderItem function creates a FolderItem object for a specific item (application, document, or folder). GetFolderItem can be passed a file name for a specific item or an empty string. If you want to access an item via an absolute path, use the Volume function and the Child method of the FolderItem class.

If you intend to open an existing file with GetFolderItem, you should check the Exists property of the FolderItem to be sure that the file actually exists before accessing that FolderItem's properties.

Passing an empty string returns a FolderItem representing the folder the project is in. If you haven't saved the project, it returns the folder that the Real Studio application is in.

For Mac OS X Mach-O applications, GetFolderItem returns the FolderItem for the directory containing the bundle instead of a FolderItem inside of the bundle.


GetFolderItem automatically resolves aliases when filename represents an alias. To prevent this, use GetTrueFolderItem.

Examples

This example displays the name of the folder that contains the Real Studio project (or the application bundle folder if run in a compiled application on Mac OS X) in a message box.

Dim currentFolder as FolderItem
currentFolder=GetFolderItem("")
MsgBox currentFolder.name


The following example gets an item within the current directory:

Dim f as FolderItem
f=GetFolderItem("Project Templates")


The following example uses the Parent property of the FolderItem class to get the parent directory for the directory that contains the application:

Dim f as FolderItem
f=GetFolderItem("").Parent


The following example opens a TIFF file in the same folder as the application (or the same folder as Real Studio if run from the IDE) and uses it as the background image ("backdrop") for a Canvas control:

Dim f as FolderItem
f=GetFolderItem("Zippy.tif")
If f.exists then
Canvas1.backdrop=f.OpenAsPicture
end if


To get a reference using an absolute path, construct it using the Volume function and the Child method of the FolderItem class:. The example uses a Try block to handle the exception if the path is invalid.

Dim f as FolderItem
Try
f=SpecialFolder.Documents.Child("Schedule")
Catch Err as NilObjectException
MsgBox "The path is invalid!"
End Try


The following example uses the URL path to the user’s “Documents” folder on Windows:

Dim f as FolderItem
f=GetFolderItem("file:///C:/Documents%20and%20Settings/Joe%20User/My%20Documents/",FolderItem.PathTypeURL)
If f.exists then
MsgBox f.AbsolutePath
Else
MsgBox "The folderitem does not exist."
End if


The following example uses the shell path to the Documents folder on Mac OS X:

Dim f as FolderItem
f=GetFolderItem("/Users/Joe/Documents", FolderItem.PathTypeShell)
If f.exists then
TextField1.text=f.AbsolutePath
else
MsgBox "The folderitem does not exist."
End if


This example returns a FolderItem for the “Documents” folder in the home directory on Linux for user “Joe”:

Dim f as FolderItem
f=GetFolderItem("/home/Joe/Documents", FolderItem.PathTypeShell)
If f.exists then
TextField1.text=f.AbsolutePath
else
MsgBox "The folderitem does not exist."
End if

See Also

FolderItem, FolderItemDialog, RuntimeException classes; GetTrueFolderItem function; NilObjectException error; Nil object.

Personal tools