| Package | flash.filesystem |
| Class | public class File |
| Inheritance | File FileReference EventDispatcher Object |
| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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 the 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 | ||
|---|---|---|---|
[static] [read-only]
The folder containing the application's installed files. | 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 | |
[static] [read-only]
The user's desktop directory. | File | ||
[static] [read-only]
The user's documents directory. | File | ||
[read-only]
Indicates whether the referenced file or directory exists. | File | ||
![]() | [read-only]
The filename extension. | FileReference | |
[read-only]
An Icon object containing the icons defined for the file. | File | ||
[read-only]
Indicates whether the reference is to a directory. | File | ||
[read-only]
Indicates whether the referenced file or directory is "hidden."
The value is true if the referenced file or directory is hidden, false otherwise. | File | ||
[read-only]
Indicates whether the referenced directory is a package. | File | ||
[read-only]
Indicates whether the reference is a symbolic link. | File | ||
[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 | |
The full path in the host operating system representation. | 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 | |
[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 | |
[read-only]
The space available for use at this File location, in bytes. | File | ||
[static] [read-only]
The default encoding used by the host operating system. | File | ||
![]() | type : String [read-only]
The file type. | FileReference | |
The URL for this file path. | File | ||
[static] [read-only]
The user's directory. | File | ||
| Method | Defined By | ||
|---|---|---|---|
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 | |
![]() |
Displays a file-browsing dialog box that lets the
user select a file to upload. | FileReference | |
Displays a directory chooser dialog box, in which the user can select a directory. | File | ||
Displays the Open File dialog box, in which the user can select a file to open. | File | ||
Displays the Open File dialog box, in which the user can select one or more files to open. | File | ||
Displays the Save File dialog box, in which the user can select a file destination. | File | ||
Cancels any pending asynchronous operation. | File | ||
Canonicalizes the File path. | File | ||
Returns a copy of this File object. | File | ||
Copies the file or directory at the location specified by this File object to
the location specified by the newLocation parameter. | File | ||
Begins copying the file or directory at the location specified by this File object to
the location specified by the destination parameter. | File | ||
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 | ||
Deletes the directory. | File | ||
Deletes the directory asynchronously. | File | ||
Deletes the file. | File | ||
Deletes the file asynchronously. | File | ||
![]() |
Dispatches an event into the event flow. | EventDispatcher | |
![]() |
Opens a dialog box that lets the user download a file from a remote server. | FileReference | |
Returns an array of File objects corresponding to files and directories in the directory represented by this
File object. | File | ||
Asynchronously retrieves an array of File objects corresponding to the contents of the directory represented
by this File object. | File | ||
Finds the relative path between two File paths. | File | ||
[static]
Returns an array of File objects, listing the file system root directories. | File | ||
![]() |
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | |
![]() |
Indicates whether an object has a specified property defined. | Object | |
![]() |
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
Moves the file or directory at the location specified by this File object to
the location specified by the destination parameter. | File | ||
Begins moving the file or directory at the location specified by this File object to
the location specified by the newLocation parameter. | File | ||
Moves a file or directory to the trash. | File | ||
Asynchronously moves a file or directory to the trash. | File | ||
![]() |
Indicates whether the specified property exists and is enumerable. | Object | |
![]() |
Removes a listener from the EventDispatcher object. | EventDispatcher | |
Creates a new File object with a path relative to this File object's path, based on the
path parameter (a String). | File | ||
![]() |
Sets the availability of a dynamic property for loop operations. | Object | |
![]() |
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 | |
![]() |
Initiate uploading a file to a URL without any encoding. | FileReference | |
![]() |
Returns the primitive value of the specified object. | Object | |
![]() |
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 of a call to the getDirectoryListingAsync() method. | File | |||
![]() | Dispatched if a call to the upload() or uploadUnencoded() method attempts to access data over HTTP and Adobe AIR is able to detect and return the status code for the request. | FileReference | ||
![]() | 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 | |||
![]() | Dispatched when an upload or download operation starts. | FileReference | ||
![]() | Dispatched periodically during the file upload or download operation. | FileReference | ||
| Dispatched when an operation violates a security constraint. | File | |||
| Dispatched when the user selects a file or directory from a file- or directory-browsing dialog box. | File | |||
| Dispatched when the user selects files from the dialog box opened by a call to the browseForOpenMultiple() method. | File | |||
![]() | Dispatched after data is received from the server after a successful upload. | FileReference | ||
| property |
applicationDirectory:File [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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
File.applicationDirectory directory (by using the resolvePath() method),
the url property 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. Also, you cannot 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 the content in the application storage directory
to have access to the application-priveleged functionality (AIR APIs), you can expose that functionality
by using a sandbox bridge.
public static function get applicationDirectory():FileSee also
| property |
applicationStorageDirectory:File [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
The application's private storage directory.
Each AIR application has a unique, persistent application storage directory, which
is created when you first access File.applicationStorageDirectory. This directory
is a convenient location to store application-specific data.
When you uninstall an AIR application, the uninstaller does not delete files that are stored in the application storage directory.
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
File.applicationStoreDirectory directory (by using the resolvePath() method),
the url of the File object also uses the app-storage URL scheme
(as in the example).
public static function get applicationStorageDirectory():File
import flash.filesystem.File;
var tempFiles:File = File.applicationStorageDirectory;
tempFiles = tempFiles.resolvePath("images/");
trace(tempFiles.url); // app-storage:/images| property |
desktopDirectory:File [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
The user's desktop directory.
public static function get desktopDirectory():File
import flash.filesystem.File;
var desktop:File = File.desktopDirectory;
var files:Array = desktop.getDirectoryListing();
for (var i:uint = 0; i < files.length; i++) {
trace(files[i].nativePath);
}| property |
documentsDirectory:File [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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.
public static function get documentsDirectory():FileFile.documentsDirectory property and the
File.createDirectory() method to ensure that a directory named "AIR Test" exists
in the user's documents directory.
import flash.filesystem.File;
var directory:File = File.documentsDirectory;
directory = directory.resolvePath("AIR Test");
File.createDirectory(directory);
trace(directory.exists); // true| property |
exists:Boolean [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Indicates whether the referenced file or directory exists.
The value is true if the File object points to an existing file or directory,
false otherwise.
public function get exists():BooleanFile.exists property to check for the existence of the file.import flash.filesystem.*; var temp:File = File.createTempFile(); trace(temp.exists); // true temp.deleteFile(); trace(temp.exists); // false
| property |
icon:Icon [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
An Icon object containing the icons defined for the file. An Icon object is an array of BitmapData objects corresponding to the various icon states.
public function get icon():Iconicon array that has
the least height, and it sets a Bitmap object to that image.
import flash.filesystem.File;
import flash.display.*;
var directory:File = File.documentsDirectory;
var bitmaps:Array = file.icon.bitmaps;
var bmpData:BitmapData = new BitmapData(1, 1);
for (var i:uint = 0; i < bitmaps.length; i++) {
if (bitmaps[i].height > bmpData.height) {
bmpData = file.icon.bitmaps[i];
}
}
var iconBmp:Bitmap = new Bitmap(bmpData);| property |
isDirectory:Boolean [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Indicates whether the reference is to a directory.
The value is true if the File object points to a directory; false otherwise.
public function get isDirectory():BooleanisDirectory property to list only those File objects that point to
directories (not to files).
import flash.filesystem.*;
var userDirFiles:Array = File.userDirectory.getDirectoryListing();
for (var i:uint = 0; i < userDirFiles.length; i++) {
if (userDirFiles[i].isDirectory) {
trace(userDirFiles[i].nativePath);
}
} | property |
isHidden:Boolean [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Indicates whether the referenced file or directory is "hidden."
The value is true if the referenced file or directory is hidden, false otherwise.
public function get isHidden():BooleanisHidden property to list hidden files and directories.
import flash.filesystem.*;
var userDirFiles:Array = File.userDirectory.getDirectoryListing();
for (var i:uint = 0; i < userDirFiles.length; i++) {
if (userDirFiles[i].isHidden) {
trace(userDirFiles[i].nativePath);
}
} | property |
isPackage:Boolean [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Indicates whether the referenced directory is a package.
The value is true if the referenced directory is a package, false otherwise.
Note that the File class does not allow creating packages directly.
true if the referenced
directory is a package, and false if the file is not a directory, does not exists, or
is not a package.false. public function get isPackage():Boolean| property |
isSymbolicLink:Boolean [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Indicates 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.
Mac® OS® and Windows® Vista®
support symbolic links. Additionally, on Windows the isSymbolicLink
property for a File object referencing a junction point (used in the NTFS file system) is set to
true.
public function get isSymbolicLink():Boolean| property |
lineEnding:String [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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).
public static function get lineEnding():Stringstr) 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 preferred
line-ending character for the host operating system.
import flash.filesystem.*;
var str:String = "Hello\n" +
"World\n";
str = str.replace(/\n/g, File.lineEnding);
var file:File = File.documentsDirectory.resolvePath("AIR Test/test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.WRITE);
fileStream.writeUTF(str);
fileStream.close();| property |
nativePath:String [read-write] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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
by using the forward slash character or the backslash (\) character as the
path separator, and AIR automatically replaces forward slashes with
the appropriate backslash character.
public function get nativePath():String public function set nativePath(value:String):voidSecurityError — The caller is not in the application security sandbox.
| |
ArgumentError — The syntax of the path is invalid.
|
nativePath
property and the url property of a File object. The comments show results on an
example Windows computer.import flash.filesystem.File; var docs:File = File.documentsDirectory; trace(docs.nativePath); // C:\Documents and Settings\turing\My Documents trace(docs.url); // file:///C:/Documents%20and%20Settings/turing/My%20Documents
| property |
parent:File [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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 that points 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.
public function get parent():Fileparent property to show the directory
that contains a temporary file.import flash.filesystem.File; var tempFile:File = File.createTempDirectory(); trace(tempFile.parent.nativePath); tempFile.deleteFile();
| property |
separator:String [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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.
public static function get separator():StringgetRelativePath() 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.
import flash.filesystem.File;
var directory:File = File.documentsDirectory.resolvePath("Apollo Test");
var file:File = File.documentsDirectory.resolvePath("Apollo Test/employees/bob/test.txt");
var relativePath:String = directory.getRelativePath(file); // employees/bob/test.txt
relativePath = relativePath.replace(/\//g, File.separator);
trace(relativePath); replace() method uses a regular expression,
/\//g, to match all forward slash characters.| property |
spaceAvailable:Number [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.1 |
The space available for use at this File location, in bytes.
If the File object references a directory,
spaceAvailable indicates the space in the directory that files can use. If
the File object references a file, spaceAvailable indicates the space into which the file
could grow. If the file location does not exist, spaceAvailable is set to 0. If the File
object references a symbolic link, spaceAvailable indicates the space available at the
location the symbolic link points to.
Typically the space available for a directory or file is the same as the space available on the volume containing the directory or file. However, space available can take into account quotas and per-directory limits.
Adding a file or directory to a volume generally requires more space than the actual size of the file or the size of the contents of the directory. For example, the operating system may require more space to store index information. Or the disk sectors required may use additional space. Also, available space changes dynamically. So, you cannot expect to allocate all of the reported space for file storage.
public function get spaceAvailable():Number| property |
systemCharset:String [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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 can use this value when using the readMultiByte() and writeMultiByte()
methods of the FileStream class.
public static function get systemCharset():StringSee also
File.systemCharset static property
as the charSet parameter of a call to the readMultiByte() method
of a FileStream object.
import flash.filesystem.File;
var file:File = File.documentsDirectory.resolvePath("AIR Test/test.txt");
var fileStream:FileStream = new FileStream();
fileStream.open(file, FileMode.READ);
var str:String = fileStream.readMultiByte(file.size, File.systemCharset);
trace(str); | property |
url:String [read-write] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
The URL for this file path.
If this is a reference to a path in the application storage directory, the URL scheme is
"app-storage"; if it is a reference to a path in the application directory, the
URL scheme is "app"; otherwise the scheme is "file".
You can use blank space characters (rather than "%20") when
assigning a value to the url property; AIR automatically
encodes the strings (for instance, converting spaces to "%20").
public function get url():String public function set url(value:String):voidArgumentError — The URL syntax is invalid.
| |
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.import flash.filesystem.File; var docs:File = File.documentsDirectory; trace(docs.nativePath); // C:\Documents and Settings\turing\My Documents trace(docs.url); // file:///C:/Documents%20and%20Settings/turing/My%20Documents
| property |
userDirectory:File [read-only] | Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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.
public static function get userDirectory():File
import flash.filesystem.File;
var files:Array = File.userDirectory.listDirectory();
for (var i:uint = 0; i < files.length; i++) {
trace(files[i].nativePath);
}| () | Constructor |
public function File(path:String = null)| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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 by using either a URL or
native path (platform-specific) notation.
If you specify a URL, you can use any of the following
URL schemes:
The If you specify a native path, on Windows you can use either the backslash character or
the forward slash character as the path separator in this argument; on Mac OS, use the
forward slash. The following are valid values for the
However, for these two examples, you should pass no |
ArgumentError — The syntax of the path parameter is invalid.
|
See also
| () | method |
public function browseForDirectory(title:String):void| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Displays a directory chooser dialog box, in which the user can 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. When the directory is selected, the code lists the contents of
the selected directory in the trace() output.
import flash.filesystem.File;
import flash.events.Event;
var directory:File = File.documentsDirectory;
try
{
directory.browseForDirectory("Select Directory");
directory.addEventListener(Event.SELECT, directorySelected);
}
catch (error:Error)
{
trace("Failed:", error.message);
}
function directorySelected(event:Event):void
{
directory = event.target as File;
var files:Array = directory.getDirectoryListing();
for(var i:uint = 0; i < files.length; i++)
{
trace(files[i].name);
}
}| () | method |
public function browseForOpen(title:String, typeFilter:Array = null):void| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Displays the Open File dialog box, in which the user can 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. When the file is selected, the code reads the file data
into a string.
import flash.filesystem.*;
import flash.events.Event;
import flash.net.FileFilter;
var fileToOpen:File = new File();
var txtFilter:FileFilter = new FileFilter("Text", "*.as;*.css;*.html;*.txt;*.xml");
try
{
fileToOpen.browseForOpen("Open", [txtFilter]);
fileToOpen.addEventListener(Event.SELECT, fileSelected);
}
catch (error:Error)
{
trace("Failed:", error.message);
}
function fileSelected(event:Event):void
{
var stream:FileStream = new FileStream();
stream.open(event.target, FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
trace(fileData);
}| () | method |
public function browseForOpenMultiple(title:String, typeFilter:Array = null):void| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Displays the Open File dialog box, in which the user can 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(), with the browseForOpenMultiple()
method, this File object is not updated to reference any of the chosen files.
Instead, the resulting selectMultiple event 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 files and closes the Open File dialog box. |
See also
File.browseForOpenMultiple() method to
let the user choose multiple files. When the files are selected, the code outputs the paths
for the selected files.
import flash.filesystem.*;
import flash.events.FileListEvent;
var docsDir:File = File.documentsDirectory;
try
{
docsDir.browseForOpenMultiple("Select Files");
docsDir.addEventListener(FileListEvent.SELECT_MULTIPLE, filesSelected);
}
catch (error:Error)
{
trace("Failed:", error.message);
}
function filesSelected(event:FileListEvent):void
{
for (var i:uint = 0; i < event.files.length; i++)
{
trace(event.files[i].nativePath);
}
}| () | method |
public function browseForSave(title:String):void| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Displays the Save File dialog box, in which the user can select a file destination.
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. When the files are selected, the code saves
data to the selected file path.
import flash.filesystem.*;
import flash.events.Event;
var docsDir:File = File.documentsDirectory;
try
{
docsDir.browseForSave("Save As");
docsDir.addEventListener(Event.SELECT, saveData);
}
catch (error:Error)
{
trace("Failed:", error.message);
}
function saveData(event:Event):void
{
var newFile:File = event.target as File;
var str:String = "Hello.";
if (!newFile.exists)
{
var stream:FileStream = new FileStream();
stream.open(newFile, FileMode.WRITE);
stream.writeUTFBytes(str);
stream.close();
}
}
| () | method |
override public function cancel():void| Runtime Versions : | AIR 1.0 |
Cancels any pending asynchronous operation.
| () | method |
public function canonicalize():void| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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 filesnames to long filenames 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.
import flash.filesystem.*;
var path:File = File.desktopDirectory.resolvePath("air test");
trace(path.nativePath);
path.canonicalize();
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.import flash.filesystem.*; var path:File = new File(); path.nativePath = "C:\\AIR~1"; path.canonicalize(); trace(path.nativePath); // C:\AIR Test
| () | method |
public function clone():File| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
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 ActionScript™
File object. To copy a file, use the
copyTo() method.
File |
| () | method |
public function copyTo(newLocation:FileReference, overwrite:Boolean = false):void| Language Version : | ActionScript 3.0 |
| Runtime Versions : | AIR 1.0 |
Copies the file or directory at the location specified by this File object to
the location specified by the newLocation parameter. The copy process
creates any required parent directories (if possible).
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 fails if the file specified by the target
parameter already exists. If true, the operation overwrites existing file or directory
of the same name.
|
IOError — The source does not exist; or the destination exists and overwrite is false;
or the source could not be copied to the target; or the source and destination refer to the same file or folder and
overwrite is set to true. On Windows, you cannot copy a file that is open or a directory
that contains a file that is open.
|
See also