AIR has made it easy to work with the local file system of the client machine. Once an application is installed and has the required permissions, then creating, updating, moving, and deleting files or directories is done through an API. This is an important fact since, because the commands are issued through an API, the AIR runtime ensures that the file system change requests will work on whatever operating system/version the application is installed on.
The following examples demonstrate how to use the File API to make changes to the file system. These examples use the flash.filesystem.File class for interactions with the file system. The next group of samples will work with the same project and build on it with each new piece of functionality. To get started, create a new AIR project and name it Chapter8_Dir. You should now have an empty file named Chapter8_Dir.mxml that looks like Listing 8-1. Please note that the completed source code for Chapter8_Dir.mxml is available in Listing 8-3.
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> </mx:WindowedApplication>
The first set of functionality that we will explore will be the creation of a new directory. To create a new directory, you must first add an <mx:Script> block to the Chapter8_Dir.mxml ...