13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Working with the file system<br />

File.docum<strong>en</strong>tsDirectory.resolvePath("test.txt");<br />

File.docum<strong>en</strong>tsDirectory.resolvePath("TeSt.TxT");<br />

However, docum<strong>en</strong>ts and directory names do include capitalization. For example, the following assumes that there is<br />

a folder named AIR Test in the docum<strong>en</strong>ts directory, as in the following examples:<br />

var file:File = File.docum<strong>en</strong>tsDirectory.resolvePath("AIR test");<br />

trace(file.nativePath); // ... AIR test<br />

file.canonicalize();<br />

trace(file.nativePath); // ... AIR Test<br />

The canonicalize() method converts the nativePath object to use the correct capitalization for the file or directory<br />

name. On case s<strong>en</strong>sitive file systems (such as Linux), wh<strong>en</strong> multiple files exists with names differing only in case, the<br />

canonicalize() method adjusts the path to match the first file found (in an order determined by the file system).<br />

You can also use the canonicalize() method to convert short file names ("8.3" names) to long file names on<br />

Windows, as in the following examples:<br />

var path:File = new File();<br />

path.nativePath = "C:\\AIR~1";<br />

path.canonicalize();<br />

trace(path.nativePath); // C:\AIR Test<br />

Working with packages and symbolic links<br />

Adobe AIR 1.0 and later<br />

Various operating systems support package files and symbolic link files:<br />

Packages—On Mac OS, directories can be designated as packages and show up in the Mac OS Finder as a single file<br />

rather than as a directory.<br />

Symbolic links—Mac OS, Linux, and Windows Vista support symbolic links. Symbolic links allow a file to point to<br />

another file or directory on disk. Although similar, symbolic links are not the same as aliases. An alias is always<br />

reported as a file (rather than a directory), and reading or writing to an alias or shortcut never affects the original file<br />

or directory that it points to. On the other hand, a symbolic link behaves exactly like the file or directory it points to.<br />

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<br />

points to, not the symbolic link itself. Additionally, on Windows the isSymbolicLink property for a File object<br />

refer<strong>en</strong>cing a junction point (used in the NTFS file system) is set to true.<br />

The File class includes the isPackage and isSymbolicLink properties for checking if a File object refer<strong>en</strong>ces a<br />

package or symbolic link.<br />

The following code iterates through the user’s desktop directory, listing subdirectories that are not packages:<br />

var desktopNodes:Array = File.desktopDirectory.getDirectoryListing();<br />

for (var i:uint = 0; i < desktopNodes.l<strong>en</strong>gth; i++)<br />

{<br />

if (desktopNodes[i].isDirectory && !!desktopNodes[i].isPackage)<br />

{<br />

trace(desktopNodes[i].name);<br />

}<br />

}<br />

The following code iterates through the user’s desktop directory, listing files and directories that are not symbolic links:<br />

Last updated 6/6/2012<br />

678

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!