| window.runtime property | window.runtime.flash.filesystem.File |
| Inheritance | File FileReference EventDispatcher Object |
The File class has a number of properties and methods for getting information about the file system and for performing operations (such as copying files and directories).
You can use File objects along with FileStream class to read and write files.
The File class extends the FileReference class. The FileReference class, which is available in Flash Player as well as Adobe AIR, represents a pointer to a file, but the File class adds properties and methods that are not exposed in Flash Player (in a SWF running in a browser), due to security considerations.
See also
| Property | Defined By | ||
|---|---|---|---|
| applicationDirectory : File
[static] [read-only]
The folder containing the application's installed files.
| File | ||
| applicationStorageDirectory : File
[static] [read-only]
The application's private storage directory.
| File | ||
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance.
| Object | |
![]() | creationDate : Date
[read-only]
The creation date of the file on the local disk.
| FileReference | |
![]() | creator : String
[read-only]
The Macintosh creator type of the file, which is only used in Mac OS versions
prior to Mac OS X.
| FileReference | |
| desktopDirectory : File
[static] [read-only]
The user's desktop directory.
| File | ||
| documentsDirectory : File
[static] [read-only]
The user's documents directory.
| File | ||
| exists : Boolean
[read-only]
Whether the referenced file or directory exists.
| File | ||
![]() | extension : String
[read-only]
The filename extension.
| FileReference | |
| icon : Icon
[read-only]
An Icon object containing to the icons defined for the file.
| File | ||
| isDirectory : Boolean
[read-only]
Whether the reference is to a directory.
| File | ||
| isHidden : Boolean
[read-only]
Whether the referenced file or directory is "hidden."
The value is true if the referenced file or directory is hidden; and false otherwise.
| File | ||
| isPackage : Boolean
[read-only]
Whether the referenced directory is a package.
| File | ||
| isSymbolicLink : Boolean
[read-only]
Whether the reference is a symbolic link.
| File | ||
| lineEnding : String
[static] [read-only]
The line-ending character sequence used by the host operating system.
| File | ||
![]() | modificationDate : Date
[read-only]
The date that the file on the local disk was last modified.
| FileReference | |
![]() | name : String
[read-only]
The name of the file on the local disk.
| FileReference | |
| nativePath : String
The full path in the host operating system representation.
| File | ||
| parent : File
[read-only]
The directory that contains the file or directory referenced by this File object.
| File | ||
![]() | prototype : Object
[static]
A reference to the prototype object of a class or function object.
| Object | |
| separator : String
[static] [read-only]
The host operating system's path component separator character.
| File | ||
![]() | size : Number
[read-only]
The size of the file on the local disk in bytes.
| FileReference | |
| systemCharset : String
[static] [read-only]
The default encoding used by the host operating system.
| File | ||
![]() | type : String
[read-only]
The file type.
| FileReference | |
| url : String
The URL for this File path.
| File | ||
| userDirectory : File
[static] [read-only]
The user's directory.
| File | ||
| Method | Defined By | ||
|---|---|---|---|
|
File(path:String = null)
The constructor function for the File class.
| File | ||
![]() |
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event.
| EventDispatcher | |
![]() |
browse(typeFilter:Array = null):Boolean
Displays a file-browsing dialog box that lets the
user select a file to upload.
| FileReference | |
|
browseForDirectory(title:String):void
Displays a directory chooser dialog box, which lets the user select a directory.
| File | ||
|
browseForOpen(title:String, typeFilter:Array = null):void
Displays an Open File dialog box, which lets the user select a file to open.
| File | ||
|
browseForOpenMultiple(title:String, typeFilter:Array = null):void
Displays an Open File dialog box, which lets the user select one or more files to open.
| File | ||
|
browseForSave(title:String):void
Displays a Save File dialog box, which lets the user select a file desitination.
| File | ||
|
cancel():void
Cancels any pending asynchronous operation.
| File | ||
|
canonicalize():void
Canonicalizes the File path.
| File | ||
|
Returns a copy of this File object.
| File | ||
|
copyTo(newLocation:FileReference, overwrite:Boolean = false):void
Copies the file or directory at the location specified by this File object to
the location specified by newLocation parameter.
| File | ||
|
copyToAsync(newLocation:FileReference, overwrite:Boolean = false):void
Begins copying the file or directory at the location specified by this File object to
the location specified by the destination parameter.
| File | ||
|
createDirectory():void
Creates the specified directory and any necessary parent directories.
| File | ||
|
[static]
Returns a reference to a new temporary directory.
| File | ||
|
[static]
Returns a reference to a new temporary file.
| File | ||
|
deleteDirectory(deleteDirectoryContents:Boolean = false):void
Deletes the directory.
| File | ||
|
deleteDirectoryAsync(deleteDirectoryContents:Boolean = false):void
Deletes the directory asynchronously.
| File | ||
|
deleteFile():void
Deletes the file.
| File | ||
|
deleteFileAsync():void
Deletes the file asynchronously.
| File | ||
![]() |
dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow.
| EventDispatcher | |
![]() |
download(request:URLRequest, defaultFileName:String = null):void
Opens a dialog box that lets the user download a file from a remote server.
| FileReference | |
|
getDirectoryListing():Array
Returns an array of File objects corresponding to files and directories in the directory represented by this
File object.
| File | ||
|
getDirectoryListingAsync():void
Asynchronously retrieves an array of File objects corresponding to the contents of the directory represented
by this File object.
| File | ||
|
getRelativePath(ref:FileReference, useDotDot:Boolean = false):String
Finds relative path between two File paths.
| File | ||
|
getRootDirectories():Array
[static]
Returns an array of file system root directories.
| File | ||
![]() |
hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event.
| EventDispatcher | |
![]() |
hasOwnProperty(name:String):Boolean
Indicates whether an object has a specified property defined.
| Object | |
![]() |
isPrototypeOf(theClass:Object):Boolean
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter.
| Object | |
|
moveTo(newLocation:FileReference, overwrite:Boolean = false):void
Moves the file or directory at the location specified by this File object to
the location specified by the destination parameter.
| File | ||
|
moveToAsync(newLocation:FileReference, overwrite:Boolean = false):void
Begins moving the file or directory at the location specified by this File object to
the location specified by the newLocation parameter.
| File | ||
|
moveToTrash():void
Moves a file or directory to the trash.
| File | ||
|
moveToTrashAsync():void
Asynchronously moves a file or directory to the Trash.
| File | ||
![]() |
propertyIsEnumerable(name:String):Boolean
Indicates whether the specified property exists and is enumerable.
| Object | |
![]() |
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
| EventDispatcher | |
|
resolvePath(path:String):File
Creates a new File object with a path relative to this File object's path, based on the
path parameter (a String).
| File | ||
![]() |
setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Sets the availability of a dynamic property for loop operations.
| Object | |
![]() |
toString():String
Returns the string representation of the specified object.
| Object | |
![]() |
upload(request:URLRequest, uploadDataFieldName:String = "Filedata", testUpload:Boolean = false):void
Starts the upload of a file selected by a user to a remote server.
| FileReference | |
![]() |
uploadUnencoded(request:URLRequest):void
Initiate uploading a file to a URL without any encoding.
| FileReference | |
![]() |
valueOf():Object
Returns the primitive value of the specified object.
| Object | |
![]() |
willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type.
| EventDispatcher | |
| Event | Summary | Defined By | ||
|---|---|---|---|---|
![]() | Dispatched when Flash Player or an AIR application gains operating system focus and becomes active. | EventDispatcher | ||
| Dispatched when a pending asynchronous operation is canceled. | File | |||
| Dispatched when an asynchronous operation is complete. | File | |||
![]() | Dispatched when Flash Player or an AIR application loses operating system focus and is becoming inactive. | EventDispatcher | ||
| Dispatched when a directory list is available as a result to a call to the getDirectoryListingAsync() method. | File | |||
![]() |
httpResponseStatus
| Dispatched when an upload is successful. | FileReference | |
![]() |
httpStatus
| Dispatched when an upload fails and an HTTP status code is available to describe the failure. | FileReference | |
| Dispatched when an error occurs during an asynchronous file operation. | File | |||
![]() |
open
| Dispatched when an upload or download operation starts. | FileReference | |
![]() |
progress
| Dispatched periodically during the file upload or download operation. | FileReference | |
| Dispatched when a an operation violates a security constraint. | File | |||
| Dispatched when the user selects a file or directory from the a file- or directory-browsing dialog box. | File | |||
| Dispatched when the user selects a files from the browseForOpenMultiple() dialog box. | File | |||
![]() |
uploadCompleteData
| Dispatched after data is received from the server after a successful upload. | FileReference | |
| applicationDirectory | property |
applicationDirectory:File [read-only] The folder containing the application's installed files.
The url property for this object uses the app URL scheme
(not the file URL scheme). This means that the url string is specified starting
with "app:" (not file:). Also, if you create a File object relative to the
applicationDirectory directory (using the resolvePath() method),
the url of the File object also uses the app URL scheme.
Note: You cannot write to files or directories that have paths that use the app
URL scheme. Nor can you delete or create files or folders that have paths that use the app
URL scheme. Modifying content in the application directory is a bad practice, for security reasons.
If you want to store application-specific data, consider using the application storage directory
(File.applicationStorageDirectory). If you want any of that content (in the application storage directory)
to have access to the application-priveleged functionality (AIR APIs), you can expose that functionality
using a sandbox bridge.
See also
| applicationStorageDirectory | property |
applicationStorageDirectory:File [read-only]
The application's private storage directory. Each AIR application has a unique, persistent application
storage directory, which is created when you first access applicationStorageDirectory. This directory
is a convenient location to store application-specific data.
The url property for this object uses the app-storage URL scheme
(not the file URL scheme). This means that the url string is specified starting
with "app-storage:" (not file:). Also, if you create a File object relative to the
applicationStoreDirectory directory (using the resolvePath() method),
the url of the File object also uses the app-storage URL scheme
(as in the example).
var tempFiles = air.File.applicationStorageDirectory;
tempFiles = tempFiles.resolvePath("images/");
air.trace(tempFiles.url); // app-storage:/images| desktopDirectory | property |
desktopDirectory:File [read-only] The user's desktop directory.
var desktop = air.File.desktopDirectory;
var files = desktop.getDirectoryListing()
for (i = 0; i < files.length; i++) {
air.trace(files[i].nativePath)
}| documentsDirectory | property |
documentsDirectory:File [read-only] The user's documents directory.
On Windows, this is the "My Documents" directory (for example, C:\Documents and Settings\userName\My Documents). On Mac OS, it is /Users/userName/Documents.
File.documentsDirectory property and the
File.createDirectory() method to ensure that a directory named "AIR Test" exists
in the user's documents directory.
var directory = air.File.documentsDirectory;
directory = directory.resolvePath("AIR Test");
air.File.createDirectory(directory);
air.trace(directory.exists); // true| exists | property |
exists:Boolean [read-only]
Whether the referenced file or directory exists.
The value is true if the File object points to an existing file or directory;
and false otherwise.
File.exists property to check for the existence of the file.var temp = air.File.createTempFile(); air.trace(temp.exists) // true temp.deleteFile(); air.trace(temp.exists) // false
| icon | property |
icon:Icon [read-only] An Icon object containing to the icons defined for the file. An Icon object is an array of BitmapData objects corresponding to the various icon states.
icon array that has
the least height, and it sets a Bitmap object to that image:
var directory = air.File.documentsDirectory;
var bitmaps = file.icon.bitmaps;
var bmpData = new BitmapData(1, 1);
for (i = 0; i < bitmaps.length; i++) {
if (bitmaps[i].height > bmpData.height) {
bmpData = file.icon.bitmaps[i];
}
}
var iconBmp = new Bitmap(bmpData);| isDirectory | property |
isDirectory:Boolean [read-only]
Whether the reference is to a directory.
The value is true if the File object points to a directory; false otherwise.
isDirectory property to list only those File objects that point to
directories (not files).
var userDirFiles = air.File.userDirectory.getDirectoryListing();
for (i = 0; i < userDirFiles.length; i++) {
if (userDirFiles[i].isDirectory) {
air.trace(userDirFiles[i].nativePath);
}
} | isHidden | property |
isHidden:Boolean [read-only]
Whether the referenced file or directory is "hidden."
The value is true if the referenced file or directory is hidden; and false otherwise.
isHidden property to list hidden files and directories.
var userDirFiles = air.File.userDirectory.getDirectoryListing();
for (i = 0; i < userDirFiles.length; i++) {
if (userDirFiles[i].isHidden) {
air.trace(userDirFiles[i].nativePath);
}
} | isPackage | property |
isPackage:Boolean [read-only]
Whether the referenced directory is a package.
The value is true if the referenced directory is a package; and false otherwise.
Note that the File class does not allow creating packages directly.
| isSymbolicLink | property |
isSymbolicLink:Boolean [read-only]
Whether the reference is a symbolic link.
The value is true if the File object is a symbolic link; false otherwise.
Note that the File class does not allow creating symbolic links directly.
Symbolic links allow a file to point to another file or directory on disk. Although similar, symbolic links are not the same as aliases on Mac OS and shortcuts on Windows. An alias or a shortcut is always reported as a file (rather than a directory), and reading or writing to an alias or shortcut never affects the original file or directory that it points to. On the other hand, a symbolic link behaves exactly like the file or directory it points to. It can be reported as a file or a directory, and reading or writing to a symbolic link affects the file or directory that it points to, not the symbolic link itself.
| lineEnding | property |
lineEnding:String [read-only] The line-ending character sequence used by the host operating system.
On Mac OS, this is the line-feed character (character code 0x0A hexadecimal). On Windows, this is the carriage return character (character code 0x0D hexadecimal) followed by the line-feed character (character code 0x0A hexadecimal).
str) to a text file, and uses the
File.lineEnding static property to replace all instances of the new-line character
(represented in the code by the regular expression /\n/g) with the prefered line
ending character for the host operating system.
var str = "Hello\n" +
"World\n";
str = str.replace(/\n/g, air.File.lineEnding);
var file = air.File.documentsDirectory.resolvePath("AIR Test/test.txt");
var fileStream = new air.FileStream();
fileStream.open(file, air.FileMode.WRITE);
fileStream.writeUTF(str);
fileStream.close();| nativePath | property |
nativePath:String [read-write]
The full path in the host operating system representation. On Mac OS,
the forward slash (/) character is used as the path separator.
However, in Windows, you can set the nativePath property
using the forward slash (/) character or the backslash (\) character as the
path separator, and AIR automatically replaces forward slashes with
the appropriate backslash (\) character.
SecurityError — The caller is not in the application security sandbox.
|
nativePath
property and the url property of a File object. The comments show results on an
example Windows computer.var docs = air.File.documentsDirectory; air.trace(docs.nativePath); // C:\Documents and Settings\turing\My Documents air.trace(docs.url); // file:///C:/Documents%20and%20Settings/turing/My%20Documents
| parent | property |
parent:File [read-only]
The directory that contains the file or directory referenced by this File object. If the file or directory does
not exist, the parent property still returns the File object pointing to the containing directory
(even if that directory does not exist).
This property is identical to the return value for resolvePath("..") except that the parent of a root
directory is null.
parent property to show the directory
that contains a temporary file.var tempFile = air.File.createTempDirectory(); air.trace(tempFile.parent.nativePath); tempFile.deleteFile();
| separator | property |
separator:String [read-only] The host operating system's path component separator character.
On Mac OS, this is the forward slash (/) character. On Windows, it is the backslash (\ character.
Note: When using the backslash character in a String literal, remember to
type the character twice (as in "directory\\file.ext"). Each pair of backslashes
in a String literal represent a single backslash in the String.
getRelativePath() method to get the relative path
between a directory and a file. The code then uses the File.separator static property
to replace forward slash (/) characters in the path with the separator character used by the operating
system, which is the backslash character (\) on Windows and the forward slash character on other
operating systems.
var directory = air.File.documentsDirectory.resolvePath("Apollo Test");
var file = air.File.documentsDirectory.resolvePath("Apollo Test/employees/bob/test.txt");
var relativePath = directory.getRelativePath(file); // employees/bob/test.txt
relativePath = relativePath.replace(/\//g, air.File.separator);
air.trace(relativePath); replace() method uses a regular expression,
/\//g, to match all forward slash characters.| systemCharset | property |
systemCharset:String [read-only]
The default encoding used by the host operating system. Possible values include "windows-1252"
"shift-jis", "cn-gb", "iso-8859-1", and others.
For a complete list, see Supported Character Sets.
You may use this value when using the readMultiByte() and writeMultiByte()
methods of the FileStream class.
See also
File.systemCharset static property
as the charSet parameter of a call to the readMultiByte() method
of a FileStream object.
var file = air.File.documentsDirectory.resolvePath("AIR Test/test.txt");
var fileStream = new air.FileStream();
fileStream.open(file, air.FileMode.READ);
var str = fileStream.readMultiByte(file.size, air.File.systemCharset);
air.trace(str); | url | property |
url:String [read-write] The URL for this File path.
If this is a reference to the persistent store, the URL scheme is "app-storage",
otherwise the scheme is "file".
You can use blank space characters (rather than "%20") when
assigning a value to the url property, and AIR automatically
encodes the strings (for instance, converting spaces to "%20").
SecurityError — The caller is not in the application security sandbox.
|
See also
nativePath
property and the url property of a File object. The comments show results on an
example Windows computer.var docs = air.File.documentsDirectory; air.trace(docs.nativePath); // C:\Documents and Settings\turing\My Documents air.trace(docs.url); // file:///C:/Documents%20and%20Settings/turing/My%20Documents
| userDirectory | property |
userDirectory:File [read-only] The user's directory.
On Windows, this is the parent of the "My Documents" directory (for example, C:\Documents and Settings\userName). On Mac OS it is /Users/userName.
var files = air.File.userDirectory.getDirectoryListing();
for (i = 0; i < files.length; i++) {
air.trace(files[i].nativePath);
}
| File | () | Constructor |
function File(path:String = null)
The constructor function for the File class. If you pass a path argument, the
File object points to the specified path, and the nativePath property and
and url property are set to reflect that path.
path:String (default = null) — The path to the file. You can specify the path using either a URL or using
native path (platform-specific) notation.
If you specify a URL, you can use any of the following
URL schemes:
Using the If you specify a native path, on Windows you can use either the backslash
(
However, for these two examples, you should pass no |
See also
| browseForDirectory | () | method |
function browseForDirectory(title:String):void
Displays a directory chooser dialog box, which lets the user select a directory.
When the user selects the directory, the select event is dispatched.
The target property of the select event is the
File object pointing to the selected directory.
Parameters
title:String — The string that is diplayed in the title bar of the dialog box.
|
cancel: — Dispatched when the user clicks the Cancel button in the Open File dialog box. |
|
select: — Dispatched when the user selects a directory and closes the directory chooser dialog box. |
See also
File.browseForDirectory() method to
let the user select a directory. Upon selecting the directory, the code lists the contents of
the selected directory in the trace() output:
var directory = air.File.documentsDirectory;
try
{
directory.browseForDirectory("Select Directory");
directory.addEventListener(air.Event.SELECT, directorySelected);
}
catch (error)
{
air.trace("Failed:", error.message)
}
function directorySelected(event)
{
directory = event.target ;
var files = directory.getDirectoryListing();
for(var i = 0; i < files.length; i++)
{
air.trace(files[i].name);
}
}
| browseForOpen | () | method |
function browseForOpen(title:String, typeFilter:Array = null):void
Displays an Open File dialog box, which lets the user select a file to open.
When the user selects the file, the select event is dispatched.
The target property of the select event is the
File object pointing to the selected file.
Parameters
title:String — The string that is diplayed in the title bar of the dialog box.
|
|
typeFilter:Array (default = null) — 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 class.
|
cancel: — Dispatched when the user clicks the Cancel button in the Open File dialog box. |
|
select: — Dispatched when the user selects a file and closes the Open File dialog box. |
See also
File.browseForOpen() method to
let the user choose a text file. Upon selecting the file, the code reads the file data
into a string:
var fileToOpen = new air.File();
var txtFilter = new air.FileFilter("Text", "*.as;*.css;*.html;*.txt;*.xml");
try
{
fileToOpen.browseForOpen("Open", [txtFilter]);
fileToOpen.addEventListener(air.Event.SELECT, fileSelected);
}
catch (error)
{
air.trace("Failed:", error.message)
}
function fileSelected(event)
{
var stream = new air.FileStream();
stream.open(event.target, air.FileMode.READ);
var fileData = stream.readUTFBytes(stream.bytesAvailable);
air.trace(fileData);
}| browseForOpenMultiple | () | method |
function browseForOpenMultiple(title:String, typeFilter:Array = null):void
Displays an Open File dialog box, which lets the user select one or more files to open.
When the user selects the files, the selectMultiple event is dispatched.
The target property of the select event is this
File object. Unlike browseForOpen(), this File object is not updated to reference any of
the chosen files. Instead, the resulting FileListEvent contains an array of the chosen Files.
Parameters
title:String — The string that is diplayed in the title bar of the dialog box.
|
|
typeFilter:Array (default = null) — 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 class.
|
cancel: — Dispatched when the user clicks the Cancel button in the Open File dialog box. |
|
selectMultiple: — Dispatched when the user selects file and closes the Open File dialog box. |
See also
File.browseForOpenMultiple() method to
let the user choose multiple files. Upon selecting the files, the code outputs the paths
for the selected files:
var docsDir = air.File.documentsDirectory;
try
{
docsDir.browseForOpenMultiple("Select Files");
docsDir.addEventListener(air.FileListEvent.SELECT_MULTIPLE, filesSelected);
}
catch (error)
{
air.trace("Failed:", error.message)
}
function filesSelected(event)
{
for (i = 0; i < event.files.length; i++)
{
air.trace(event.files[i].nativePath);
}
}| browseForSave | () | method |
function browseForSave(title:String):void
Displays a Save File dialog box, which lets the user select a file desitination.
When the user selects the file, the select event is dispatched.
The target property of the select event is the
File object pointing to the selected Save destination.
Parameters
title:String — The string that is diplayed in the title bar of the dialog box.
|
cancel: — Dispatched when the user clicks the Cancel button in the Save File dialog box. |
|
select: — Dispatched when the user selects a file and closes the Save File dialog box. |
See also
File.browseForSave() method to
let the user select a path for saving a file. Upon selecting the files, the code saves
data to the selected file path:
var docsDir = air.File.documentsDirectory;
try
{
docsDir.browseForSave("Save As");
docsDir.addEventListener(air.Event.SELECT, saveData);
}
catch (error)
{
air.trace("Failed:", error.message)
}
function saveData(event)
{
var newFile = event.target ;
var str = "Hello.";
if (!newFile.exists)
{
var stream = new air.FileStream();
stream.open(newFile, air.FileMode.WRITE);
stream.writeUTFBytes(str);
stream.close();
}
}
| cancel | () | method |
function cancel():void
Cancels any pending asynchronous operation.
| canonicalize | () | method |
function canonicalize():void
Canonicalizes the File path.
If the File object represents an existing file or directory, canonicalization adjusts the path so that it matches the case of the actual file or directory name. If the File object is a symbolic link, canonicalization adjusts the path so that it matches the file or directory that the link points to, regardless of whether the file or directory that is pointed to exists.
In addition, canonicalization converts short files names to long file names on Windows.
canonicalize() method to find the
correct capitalization of a directory name. Before running this example, create a directory named AIR Test
on the desktop of your computer.
var path = air.File.desktopDirectory.resolvePath("air test");
air.trace(path.nativePath);
path.canonicalize();
air.trace(path.nativePath); // ...\AIR Test
canonicalize() method to find the
long name of a Windows directory based on its short name. This example assumes that there is an AIR Test
directory at the root of the C: drive, and that the system has assigned the short name AIR~1 to the directory.var path = new air.File(); path.nativePath = "C:\\AIR~1"; path.canonicalize(); air.trace(path.nativePath); // C:\AIR Test
| clone | () | method |
function clone():File
Returns a copy of this File object. Event registrations are not copied.
Note: This method does not copy the file itself. It
simply makes a copy of the instance of the
JavaScript File object. To copy a file,
use the copyTo() method.
File |
| copyTo | () | method |
function copyTo(newLocation:FileReference, overwrite:Boolean = false):void
Copies the file or directory at the location specified by this File object to
the location specified by newLocation parameter.
Parameters
newLocation:FileReference — The target location of the new file. Note that this File object specifies
the resulting (copied) file or directory, not the path to the containing directory.
|
|
overwrite:Boolean (default = false) — If false, the copy will fail if the file specified by the target
parameter already exists. If true, the operation will first delete any existing file or directory
of the same name (however, you cannot copy a file or folder to its original path). (Note:
If you set this parameter to true and the source and destination File objects
point to the same path, calling this method deletes the file or directory.)
|
IOError — The source does not exist or the destination exists and overwrite is false
or the source could not be copied to the target. On Windows, you cannot copy a file that is open or a directory
that contains a file that is open.
|
See also
copyTo() method to copy a file.
Before running this code, be sure to create a test1.txt file in the AIR Test subdirectory of the documents directory on
your computer. The resulting copied file is named test2.txt, and it is also in the AIR Test subdirectory. By setting the
clobber parameter to true, the operation overwrites any existing test2.txt file.
var sourceFile = air.File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination = air.File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");
if (sourceFile.copyTo(destination, true)) {
air.trace("Done.")
}copyTo() method to copy a file.
Before running this code, be sure to create a test1.txt file in the AIR Test subdirectory of the home directory on your
computer. The resulting copied file is named test2.txt. The try and catch statements
show how to respond to errors.
var sourceFile = air.File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination = air.File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");
try
{
if (sourceFile.copyTo(destination, true)) {
}
catch (error)
{
air.trace("Error:" error.message)
}| copyToAsync | () | method |
function copyToAsync(newLocation:FileReference, overwrite:Boolean = false):void
Begins copying the file or directory at the location specified by this File object to
the location specified by the destination parameter. Upon completion, either a
complete event (successful) or an ioError event (unsucessful)
is dispatched.
Parameters
newLocation:FileReference — The target location of the new file. Note that this File object specifies
the resulting (copied) file or directory, not the path to the containing directory.
|
|
overwrite:Boolean (default = false) — If false, the copy will fail if the file specified by the target
file already exists. If true, the operation will first delete any existing file or directory
of the same name.
|
complete: — Dispatched when the file or directory has been successfully copied. |
|
ioError: — The source does not exist or the destination exists and overwrite is false or the
source could not be copied to the target. On Windows, you cannot copy a file that is open or a directory
that contains a file that is open. |
See also
copyToAsync() method to copy a file.
Before running this code, be sure to create a test1.txt file in the AIR Test subdirectory of the documents directory on your
computer. The resulting copied file is named test2.txt, and it is also in the AIR Test subdirectory. By setting the
clobber parameter to true, the operation overwrites any existing test2.txt file.
var sourceFile = air.File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination = air.File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");
var sourceFile.copyToAsync(destination, true);
sourceFile.addEventListener(air.Event.COMPLETE, fileCopiedHandler);
function fileCopiedHandler(event): void {
air.trace("Done.")
}| createDirectory | () | method |
function createDirectory():void
Creates the specified directory and any necessary parent directories. If the directory already exists, no action is taken.
IOError — The directory did not exist and could not be created.
|
createDirectory() method to ensure that
the AIR Test directory exists before the file is moved.
var source = air.File.desktopDirectory.resolvePath("test.txt");
var target = air.File.documentsDirectory.resolvePath("AIR Test/test.txt");
var targetParent = target.parent;
targetParent.createDirectory();
source.moveTo(target, true);| createTempDirectory | () | method |
function createTempDirectory():File
Returns a reference to a new temporary directory. This is a new directory in the system's temporary directory path.
This method lets you identify a new, unique directory, without having to query the system to see that the directory is new and unique.
You may want to delete the temporary directory before closing the application, since it is not deleted automatically.
ReturnsFile — A File referencing the new temporary directory.
|
See also
createTempFile() method to obtain a
reference to a new temporary directory.var temp = air.File.createTempDirectory(); air.trace(temp.nativePath);
| createTempFile | () | method |
function createTempFile():File
Returns a reference to a new temporary file. This is a new file in the system's temporary directory path.
This method lets you identify a new, unique file, without having to query the system to see that the file is new and unique.
You may want to delete the temporary file before closing the application, since it is not deleted automatically.
ReturnsFile — A File referencing the new temporary file.
|
See also
createTempFile() method to obtain a
reference to a new temporary file.var temp = air.File.createTempFile(); air.trace(temp.nativePath);
| deleteDirectory | () | method |
function deleteDirectory(deleteDirectoryContents:Boolean = false):void
Deletes the directory.
Parameters
deleteDirectoryContents:Boolean (default = false) — Whether or not to delete a directory that contains files or
subdirectories. When false, if the directory contains files or directoriess, a call to
this method throws an exception.
|
IOError — The directory does not exist or the directory could not be deleted. On Windows,
you cannot delete a directory that contains a file that is open.
|
See also
deleteDirectory() method to delete the directory.
var directory = air.File.documentsDirectory.resolvePath("Empty Junk Directory/");
air.File.createDirectory(directory);
air.trace(directory.exists); // true
directory.deleteDirectory();
air.trace(directory.exists); // false| deleteDirectoryAsync | () | method |
function deleteDirectoryAsync(deleteDirectoryContents:Boolean = false):void
Deletes the directory asynchronously.
Parameters
deleteDirectoryContents:Boolean (default = false) — Whether or not to delete a directory that contains files or
subdirectories. When false, if the directory contains files or directories,
the File object dispatches an ioError event.
|
complete: — Dispatched when the directory has been deleted successfully. |
|
ioError: — The directory does not exist or could not be deleted. On Windows,
you cannot delete a directory that contains a file that is open. |
See also
| deleteFile | () | method |
function deleteFile():void
Deletes the file.
IOError — The file does not exist or could not to be deleted. On Windows,
you cannot delete a file that is currently open.
|
See also
deleteFile()
method to delete it.var file = air.File.createTempFile(); air.trace(file.exists); // true file.deleteFile(); air.trace(file.exists); // false
| deleteFileAsync | () | method |
function deleteFileAsync():void
Deletes the file asynchronously.
complete: — Dispatched when the file has been deleted successfully. |
|
ioError: — The file does not exist or could not be deleted. On Windows,
you cannot delete a file that is currently open. |
See also
| getDirectoryListing | () | method |
function getDirectoryListing():Array
Returns an array of File objects corresponding to files and directories in the directory represented by this File object. This method does not explore the contents of subdirectories.
ReturnsArray — An array of File objects.
|
See also
getDirectoryListing() method to
enumerate the contents of the user directory.
var directory = air.File.userDirectory;
var list = directory.getDirectoryListing();
for (i = 0; i < list.length; i++) {
air.trace(list[i].nativePath);
}| getDirectoryListingAsync | () | method |
function getDirectoryListingAsync():void
Asynchronously retrieves an array of File objects corresponding to the contents of the directory represented by this File object.
ioError: — You do not have adequate permissions to read this directory, or the directory does
not exist. |
|
directoryListing: — The directory contents have been enumerated successfully. The
contents event includes a files property, which is the resulting array of File objects. |
See also
getDirectoryListingAsync() method to
enumerate the contents of the user directory.
var directory = air.File.userDirectory;
directory.getDirectoryListingAsync();
directory.addEventListener(air.FileListEvent.DIRECTORY_LISTING, directoryListingHandler);
function directoryListingHandler(event) {
var list = event.files;
for (i = 0; i < list.length; i++) {
air.trace(list[i].nativePath);
}
}
| getRelativePath | () | method |
function getRelativePath(ref:FileReference, useDotDot:Boolean = false):String
Finds relative path between two File paths.
The relative path is the list of components which may be appended to (resolved against) this reference in order to locate the second (parameter) reference. The relative path is returned using the "/" separator character.
Optionally, relative paths may include ".." references, but such a paths will not cross conspicuous volume boundaries.
Parameters
ref:FileReference — A File object against which the path is given.
|
|
useDotDot:Boolean (default = false) — Specifies whether the resulting relative path can use ".." components.
|
String — The relative path between this File and the ref file, if possible;
otherwise null.
|
ArgumentError — The reference is null.
|
|
SecurityError — The caller is not in the application security sandbox.
|
| getRootDirectories | () | method |
function getRootDirectories():Array
Returns an array of file system root directories.
ReturnsArray — An array of File objects, listing the root directories.
|
var rootDirs = air.File.getRootDirectories();
for (i = 0; i < rootDirs.length; i++) {
air.trace(rootDirs[i].nativePath)
}| moveTo | () | method |
function moveTo(newLocation:FileReference, overwrite:Boolean = false):void
Moves the file or directory at the location specified by this File object to
the location specified by the destination parameter.
To rename a file, set the destination parameter to point to a path that is
in the file's directory, but with a different filename.
Parameters
newLocation:FileReference — The target location for the move. This object specifies the path to the resulting
(moved) file or directory, not the path to the containing directory.
|
|
overwrite:Boolean (default = false) — If false, the move will fail if the target file
already exists. If true, the operation will overwrite any existing file or directory
of the same name. (Note: If you set this parameter to true and the source and
destination File objects point to the same path, calling this method deletes the file or directory.)
|
IOError — The source does not exist, or the destination exists and overwrite is
set to false, or the source file could not be moved to the target location. On Windows,
you cannot move a file that is open or a directory that contains a file that is open.
|
See also
moveTo() method to rename
a file. The original file name is test1.txt and the resulting name is test2.txt. Since both the source and destination File
object point to the same directory (the Apollo Test subdirectory of the user's documents directory), the
moveTo() method renames the file (rather than moving it to a new directory). Before running
this code, be sure to create a test1.txt file in the AIR Test subdirectory of the documents directory on your
computer. By setting the clobber parameter to true, the operation overwrites
any existing test2.txt file.
var sourceFile = air.File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination = air.File.documentsDirectory;
destination = destination.resolvePath("AIR Test/test2.txt");
try
{
sourceFile.moveTo(destination, true);
}
catch (error)
{
air.trace("Error:" error.message);
}moveTo() method to move a file.
The original file the test1.txt file in the Apollo Test subdirectory of the user's documents directory, and the
method moves the file to the Results subdirectory). Before running this code, be sure to create a
test1.txt file in the AIR Test subdirectory of the home directory on your computer. The try
and catch statements show how to respond to errors.
var sourceFile = air.File.documentsDirectory;
sourceFile = sourceFile.resolvePath("AIR Test/test1.txt");
var destination = air.File.documentsDirectory;
destination = destination.resolvePath("AIR Test/Results/test1.txt");
try
{
sourceFile.moveTo(destination, true);
}
catch (error)
{
air.trace("Error:" error.message);
}| moveToAsync | () | method |
function moveToAsync(newLocation:FileReference, overwrite:Boolean = false):void
Begins moving the file or directory at the location specified by this File object to
the location specified by the newLocation parameter.
To rename a file, set the destination parameter to point to a path that is
in the file's directory, but with a different filename
Parameters
newLocation:FileReference — The target location for the move. This object specifies the path to the resulting
(moved) file or directory, not the path to the containing directory.
|
|
overwrite:Boolean (default = false) — If false, the move will fail if the target file
already exists. If true, the operation will overwrite any existing file or directory
of the same name.
|
complete: — Dispatched when the file or directory has been successfully moved. |
|
ioError: — The source does not exist or the destination exists and overwrite is false or the
source could not be moved to the target. |
|
ioError: — You do not have adequate permissions to read the source file or to write to the
target location; or the source file is missing. On Windows, you cannot move a file that is open or a directory
that contains a file that is open. |
See also
moveToAsync() method to rename a
file. The original file name is test1.txt and the resulting name is test2.txt. Since both the source and destination File
object point to the same directory (the Apollo Test subdirectory of the user's documents directory), the
moveToAsync() method renames the file (rather than moving it to a new directory).
Before running this code, be sure to create a test1.txt file in the Apollo Test subdirectory of the documents directory on your
computer. By setting the clobber parameter to true, the operation overwrites any
existing test2.txt file.
var sourceFile = air.File.documentsDirectory;
sourceFile = sourceFile.resolvePath("Apollo Test/test1.txt");
var destination = air.File.documentsDirectory;
destination = destination.resolvePath("Apollo Test/test2.txt");
var sourceFile.moveToAsync(destination, true);
sourceFile.addEventListener(air.Event.COMPLETE, fileMoveCompleteHandler);
function fileMoveCompleteHandler(event): void
{
air.trace("Done.")
}
| moveToTrash | () | method |
function moveToTrash():void
Moves a file or directory to the trash.
IOError — The operating system did not allow the operation or the file
or directory does not exist. On Windows, you cannot move a file that is open or a directory
that contains a file that is currently open.
|
See also
| moveToTrashAsync | () | method |
function moveToTrashAsync():void
Asynchronously moves a file or directory to the Trash.
ioError: — The operating system did not allow the operation or the file
or directory does not exist. On Windows, you cannot move a file that is open or a directory
that contains a file that is currently open. |
|
complete: — Dispatched when the file or directory has been successfully moved to the trash. |
See also
| resolvePath | () | method |
function resolvePath(path:String):File
Creates a new File object with a path relative to this File object's path, based on the
path parameter (a String).
If the given path is an absolute file reference, then that path is used, otherwise the path is interpreted relative to this File object as follows.
The given path is "appended" to this path (however, use of ".." in the path
can return a resulting path that is not a child of the File object). The resulting reference need not
refer to an actual file system location. Use the forward slash (/) character as the path separator
(not \).
All resulting paths are normalized as follows:
Parameters
path:String — The path to append to this File's path.
|
File — A new File object, with the specified relative file path.
|
| cancel | Event |
flash.events.Event
flash.events.Event.CANCEL
Dispatched when a pending asynchronous operation is canceled.
TheEvent.CANCEL constant defines the value of the type property of a cancel event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | A reference to the object on which the operation is canceled. |
| complete | Event |
flash.events.Event
flash.events.Event.COMPLETE
Dispatched when an asynchronous operation is complete.
TheEvent.COMPLETE constant defines the value of the type property of a complete event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The network object that has completed loading. |