The
File class includes a
deleteDirectory()
method
and a
deleteDirectoryAsync()
method. These methods delete
directories, the first working synchronously, the second working asynchronously
(see
AIR file basics
). Both methods include a
deleteDirectoryContents
parameter
(which takes a Boolean value); when this parameter is set to
true
(the default
value is
false
) the call to the method deletes
non-empty directories; otherwise, only empty directories are deleted.
For example, the following code synchronously deletes the AIR
Test subdirectory of the user's documents directory:
var directory:File = File.documentsDirectory.resolvePath("AIR Test");
directory.deleteDirectory(true);
The following code asynchronously deletes the AIR Test subdirectory
of the user's documents directory:
var directory:File = File.documentsDirectory.resolvePath("AIR Test");
directory.addEventListener(Event.COMPLETE, completeHandler)
directory.deleteDirectoryAsync(true);
function completeHandler(event:Event):void {
trace("Deleted.")
}
Also included are the
moveToTrash()
and
moveToTrashAsync()
methods,
which you can use to move a directory to the System trash. For details,
see
Moving a file to the trash
.