A File object represents a path to a file or directory. This can be an existing file or directory, or it can be one that does not yet exist; for instance, it can represent the path to a file or directory that you plan to create.


The File object includes static properties that let you reference commonly used directory locations. These static properties include:


File.applicationStorageDirectory - a storage directory unique to each installed application

File.applicationDirectory - the read-only directory where the application is installed (along with any installed assets)

File.desktopDirectory - the user's desktop directory

File.documentsDirectory - the user's documents directory

File.userDirectory - the user directory

These properties have meaningful values on different operating systems. For example, Mac OS and Windows each have different native paths to the user's desktop directory. However, the File.desktopDirectory property points to the correct desktop directory path on each of these platforms. To write applications that work well across platforms, use these properties as the basis for referencing other files used by the application. Then use the resolvePath() method to refine the path. For example, this code points to the preferences.xml file in the application storage directory:


print(Lib.Media.FileSystem.File.applicationStorageDirectory.resolvePath("preferences.xml"))


If you use a literal native path in referencing a file, it will only work on one platform. For example, the following File object would only work on Windows:


Lib.Media.FileSystem.File.new("C:\Documents and Settings\joe\My Documents\test.txt")

The application storage directory is particularly useful. It gives an application-specific storage directory for the application. It is defined by the File.applicationStorageDirectory property.

Do not add or remove content from the application directory (where the application is installed). Doing so can break an application and invalidate the application signature. Application does not let you write to the application directory by default, because the directory is not writable to all user accounts on all operating systems. Use the application storage directory to write internal application files. Use the documents directory to write files that a user expects to use outside your application, such as edited pictures or text files.


Can be created using method new:

Lib.Media.FileSystem.File.new(path)

Creates File object.

path - (default = nil) - The path to the file. You can specify the path by using either a URL or native path (platform-specific) notation.


Created File object or Lib.Media.FileSystem.File itself has properties:

applicationDirectory

[static] [read-only] The folder containing the application's installed files.

applicationStorageDirectory

[static] [read-only] The application's private storage directory.

desktopDirectory

[static] [read-only] The user's desktop directory.

documentsDirectory

[static] [read-only] The user's documents directory.

userDirectory

[static] [read-only] The user's directory.

url

The URL for this file path.

nativePath

The full path in the host operating system representation.

preventBackup

Indicates whether or not the runtime prevents this File object from being backed up to the cloud. (iOS only)


methods:

browseForDirectory(title)

Displays a directory chooser dialog box, in which the user can select a directory. (Mac or Win)

title - The string that is displayed in the title bar of the dialog box.

browseForOpen(title, typeFilter)

Displays the Open File dialog box, in which the user can select a file to open. (Mac or Win)

title - The string that is displayed in the title bar of the dialog box.

typeFilter - (default = nil) - An array of FileFilter instances used to filter the files that are displayed in the dialog box. If you omit this parameter, all files are displayed. For more information, see the FileFilter object.

browseForSave(title)

Displays the Save File dialog box, in which the user can select a file destination. (Mac or Win)

title - The string that is displayed in the title bar of the dialog box.


Examples:


print(Lib.Media.FileSystem.File.applicationStorageDirectory.nativePath)

Created with the Personal Edition of HelpNDoc: Single source CHM, PDF, DOC and HTML Help creation