Packagecom.hippohx
Classpublic class File
InheritanceFile Inheritance HaxeBackendListener Inheritance flash.events.EventDispatcher

The File class provides access to the file system.

Unless stated otherwise, you should be able to pass full or relative paths to most of the methods if this class. But please note that if you want to use paths with backslashes "\" you MUST escape them like this "\\".



Protected Properties
 PropertyDefined by
 InheritedHAXE_BACKEND : String = ""
HAXE_BACKEND defines the ID that a Neko backend needs to use to call methods on this class (or the class extending this one).
HaxeBackendListener
Public Methods
 MethodDefined by
  
File()
Do NOT call this constructor, please use getInstance method instead.
File
  
appendToFile(filePath:String, fileContent:String):void
Appends new content to a text file.
File
  
copyDirectory(source:String, destination:String):void
Copies a directory to the new destination.
File
  
copyFile(source:String, destination:String):void
Copies source file to destination file.
File
  
createDirectory(directoryPath:String):void
Creates a directory in the given path.
File
  
deleteDirectory(directoryPath:String):void
Deletes a directory.
File
  
deleteFile(filePath:String):void
Deletes a file.
File
  
fileExists(filePath:String):Boolean
Checks if a file exists.
File
  
fullPath(relPath:String):String
Given an item's relative path, it returns the full path to the item.
File
 Inherited
Returns HAXE_BACKEND API identifier.
HaxeBackendListener
  
[static] Use this method to retrieve an instance of the class, do NOT call the constructor directly.
File
  
isDirectory(directoryPath:String):Boolean
Checks if a specific path is a directory or not.
File
  
isDirectoryEmpty(directoryPath:String):Boolean
Checks if a directory is empty.
File
  
openBrowserWindow(filePath:String):void
Opens a URL (either local or remote) in the default browser.
File
  
openFile(filePath:String, args:Array = null):void
Launches any file on the system with the default application.
File
  
readDirectory(directoryPath:String):Array
Reads a directory and returns an array of FileKind objects.
File
  
readFile(filePath:String):String
Reads the content of a text file.
File
  
renameFile(path:String, newName:String):String
Renames source file to new name.
File
  
search(path:String, regexp:String, regexpOptions:String = "", recursive:Boolean = false):Array
Searchs on a given path for folders and files matching a regular expression.
File
  
writefile(filePath:String, fileContent:String):void
Writes a text file to the system.
File
Constructor detail
File()constructor
public function File()

Do NOT call this constructor, please use getInstance method instead.

See also

Method detail
appendToFile()method
public function appendToFile(filePath:String, fileContent:String):void

Appends new content to a text file.

Neko call is neko.io.File.append(filePath,false);.

Parameters
filePath:String — A string with the path to the file you want to append content to.
 
fileContent:String — A string with the content you want to append.
copyDirectory()method 
public function copyDirectory(source:String, destination:String):void

Copies a directory to the new destination. The copy is recursive.

The destination directory is automatically created before making the copy, so it shoudn't exist before. If you want to copy "C:\Program Files\MyDir" to "C:\Program Files\MySecondDir", "MySecondDir" shouldn't exist previous to the call. Do it like this:

File.getInstance().createDirectory("C:\\Program Files\\MyDir","C:\\Program Files\\MySecondDir");

PLEASE note that currently there's a bug regarding this method: File.copyDirectory doesn't copy .svn folders.

Parameters
source:String — Directory to be copied.
 
destination:String — Destination directory. MUST NOT exist before the call, it's automatically created.
copyFile()method 
public function copyFile(source:String, destination:String):void

Copies source file to destination file. If destination file exists, it will be overwritten.

Neko call is neko.io.File.copy(source,destination);.

Parameters
source:String — Path to the the original file.
 
destination:String — Path to the destination file.
createDirectory()method 
public function createDirectory(directoryPath:String):void

Creates a directory in the given path. You have to include the name of the new directory in the path. So if you want to create a directory called "MyDir" on "C:\Program Files" you have to use something like:

File.getInstance().createDirectory("C:\\Program Files\\MyDir");

Parameters
directoryPath:String — A String with the path of the directory you want to create.
deleteDirectory()method 
public function deleteDirectory(directoryPath:String):void

Deletes a directory. The directory MUST be empty before deleting it.

Parameters
directoryPath:String — The path of the directory to be deleted.

See also

deleteFile()method 
public function deleteFile(filePath:String):void

Deletes a file.

Neko call is neko.FileSystem.deleteFile(filePath);.

Parameters
filePath:String — A String with the path to the file to be deleted.
fileExists()method 
public function fileExists(filePath:String):Boolean

Checks if a file exists.

Neko call is neko.FileSystem.exists(filePath);.

Parameters
filePath:String — A String with the path to the file to be checked.

Returns
Boolean — true if the file exists, false otherwise.
fullPath()method 
public function fullPath(relPath:String):String

Given an item's relative path, it returns the full path to the item.

Parameters
relPath:String — Relative path to an item (file or folder).

Returns
String — A String with the absolute path to the same item.
getInstance()method 
public static function getInstance():File

Use this method to retrieve an instance of the class, do NOT call the constructor directly. Note that you don't need to store the instance to access its methods, you can simply do this:

var exists:Boolean = File.getInstance().fileExists(filePath);

Returns
File
isDirectory()method 
public function isDirectory(directoryPath:String):Boolean

Checks if a specific path is a directory or not.

Neko call is neko.FileSystem.isDirectory(directoryPath);.

Parameters
directoryPath:String — A String with the path you want to check.

Returns
Boolean — true if the path is directory, false otherwise.
isDirectoryEmpty()method 
public function isDirectoryEmpty(directoryPath:String):Boolean

Checks if a directory is empty. You might want to use this before trying to delete one, as currently directories can only be removed if empty.

Parameters
directoryPath:String — A String with the path to the directory you want to check.

Returns
Boolean — true if there are no items on the directory, false otherwise.

See also

openBrowserWindow()method 
public function openBrowserWindow(filePath:String):void

Opens a URL (either local or remote) in the default browser.

Neko call is systools.Browser.launch(filePath);.

Parameters
filePath:String — The path to the file, either full or relative.
openFile()method 
public function openFile(filePath:String, args:Array = null):void

Launches any file on the system with the default application.

Neko call is neko.Sys.command('"start" ' + filePath,args);.

Parameters
filePath:String — The path to the file, either full or relative.
 
args:Array (default = null) — Array of Strings that would be passed as parameters to the file opened.
readDirectory()method 
public function readDirectory(directoryPath:String):Array

Reads a directory and returns an array of FileKind objects. Please note that this method will NOT return fullpaths, only the names of the items (files and folders) in it.

Neko call is neko.FileSystem.readDirectory(directoryPath); plus later creation of FileKind objects.

Parameters
directoryPath:String — A String with the path of the directory you want to check.

Returns
Array — Array of FileKind objects.

See also

readFile()method 
public function readFile(filePath:String):String

Reads the content of a text file.

Neko call is neko.io.File.read(filePath,false);.

Parameters
filePath:String — A String with the path to the file to be read.

Returns
String — A String with the content of the file.
renameFile()method 
public function renameFile(path:String, newName:String):String

Renames source file to new name. The new file will be created in the same folder as the original.

Neko call is neko.FileSystem.rename(path,newPath);.

Parameters
path:String — Path to the the original file. The new file will be created in the same folder as the original.
 
newName:String — Path to the the original file.

Returns
String — The full path to the new file.
search()method 
public function search(path:String, regexp:String, regexpOptions:String = "", recursive:Boolean = false):Array

Searchs on a given path for folders and files matching a regular expression. See Regexp tutorial on haXe site for more info.

Parameters
path:String — Initial path.
 
regexp:String — Regular expression to match folders and file names. Please note that as opposed to haXe you don't have to start your expression with "~/" and end it with "/".
 
regexpOptions:String (default = "") — Options are "i" (case insensitive), "g" (global replace or split), "m" (multiline matching), "s" ("." will match also newlines). Pass them together as a single string, i.e. "mi" for multiline matching and case-insensitive.
 
recursive:Boolean (default = false) — When set to true the search will be extended to the folders inside the initial path. Think about performance when searching recursively.

Returns
Array — An Array of Strings with the paths to the files/folders that match the regular expression.
writefile()method 
public function writefile(filePath:String, fileContent:String):void

Writes a text file to the system.

Neko call is neko.io.File.write(filePath,false);.

Parameters
filePath:String — A String with the path to the file to be written.
 
fileContent:String — A String with the content of the file.