File
The File object allows you to read and write a file.
Functions
File
Syntax
var myObject = new File();
Example
Create a File object.
var myObject = new File();
copy
Syntax
File.copy(source, destination);
File.copy(source, destination, options);
Arguments
source - (string) the source file to copy
destination - (string) the destination file/directory
options - (object) [Added in Actionaz 3.0.1.]
noErrorDialog - (bool) should an error dialog be shown if an error occurs (Windows only, default: true)
noConfirmDialog - (bool) should a confirmation dialog be shown if needed (Windows only, default: true)
noProgressDialog - (bool) should a progress dialog be shown (Windows only, default: true)
createDestinationDirectory - (bool) should the destination directory be created if it doesn't exist (Linux only, default: true)
Returns
Exceptions
(ParameterCountError) incorrect parameter count
(DirectoryCreationError) unable to create the destination directory (Linux only)
(DirectoryDoesntExistError) the destination directory doesn't exist (Linux only)
(CopyError) copy failed
(CopyAbortedError) copy aborted (Windows only)
move
Syntax
File.move(source, destination);
File.move(source, destination, options);
Arguments
source - (string) the source file to move
destination - (string) the destination file/directory
options - (object) [Added in Actionaz 3.0.1.]
noErrorDialog - (bool) should an error dialog be shown if an error occurs (Windows only, default: true)
noConfirmDialog - (bool) should a confirmation dialog be shown if needed (Windows only, default: true)
noProgressDialog - (bool) should a progress dialog be shown (Windows only, default: true)
createDestinationDirectory - (bool) should the destination directory be created if it doesn't exist (Linux only, default: true)
Returns
Exceptions
(ParameterCountError) incorrect parameter count
(DirectoryCreationError) unable to create the destination directory (Linux only)
(DirectoryDoesntExistError) the destination directory doesn't exist (Linux only)
(MoveError) move failed
(MoveAbortedError) move aborted (Windows only)
rename
This function is an alias of the move function.
remove
Syntax
File.remove(filename);
File.remove(filename, options);
Arguments
filename - (string) the file to remove
options - (object) [Added in Actionaz 3.0.1.]
noErrorDialog - (bool) should an error dialog be shown if an error occurs (Windows only, default: true)
noConfirmDialog - (bool) should a confirmation dialog be shown if needed (Windows only, default: true)
noProgressDialog - (bool) should a progress dialog be shown (Windows only, default: true)
allowUndo - (bool) should the file/directory be moved to the trash bin (Windows only, default: false)
Returns
Exceptions
(ParameterCountError) incorrect parameter count
(RemoveError) remove failed
(RemoveAbortedError) remove aborted (Windows only)
Methods
open
Syntax
myObject.open(filename, openMode);
Arguments
filename - (string) the filename of the file to open
-
Returns
Exceptions
write
Write raw data to this File.
Syntax
myObject.write(data);
myObject.write(other);
Arguments
-
other - (mixed) the data to write
Returns
Exceptions
writeText
Syntax
myObject.writeText(text);
myObject.writeText(text, encoding);
Arguments
text - (string) the text to write
encoding - (
Encoding) the encoding to use
Returns
Exceptions
read
Read raw data from this File.
Syntax
Returns
(
RawData) the raw data read from the file
readText
Read text from this File.
Syntax
myObject.readText();
myObject.readText(encoding);
Arguments
encoding - (
Encoding) the encoding to use
Returns
close
Syntax
Returns
copy
Copy this file to another location.
Syntax
myObject.copy(destination);
myObject.copy(destination, options);
Arguments
destination - (string) the location where to copy the file
options - (object) [Added in Actionaz 3.0.1.]
noErrorDialog - (bool) should an error dialog be shown if an error occurs (Windows only, default: true)
noConfirmDialog - (bool) should a confirmation dialog be shown if needed (Windows only, default: true)
noProgressDialog - (bool) should a progress dialog be shown (Windows only, default: true)
createDestinationDirectory - (bool) should the destination directory be created if it doesn't exist (Linux only, default: true)
Returns
Exceptions
(ParameterCountError) incorrect parameter count
(DirectoryCreationError) unable to create the destination directory (Linux only)
(DirectoryDoesntExistError) the destination directory doesn't exist (Linux only)
(CopyError) copy failed
(CopyAbortedError) copy aborted (Windows only)
move
Move this file to another location.
Syntax
myObject.move(destination);
myObject.move(destination, options);
Arguments
destination - (string) the location where to move the file
options - (object) [Added in Actionaz 3.0.1.]
noErrorDialog - (bool) should an error dialog be shown if an error occurs (Windows only, default: true)
noConfirmDialog - (bool) should a confirmation dialog be shown if needed (Windows only, default: true)
noProgressDialog - (bool) should a progress dialog be shown (Windows only, default: true)
createDestinationDirectory - (bool) should the destination directory be created if it doesn't exist (Linux only, default: true)
Returns
Exceptions
(ParameterCountError) incorrect parameter count
(DirectoryCreationError) unable to create the destination directory (Linux only)
(DirectoryDoesntExistError) the destination directory doesn't exist (Linux only)
(MoveError) move failed
(MoveAbortedError) move aborted (Windows only)
rename
This method is an alias of the move method.
remove
Syntax
myObject.remove();
myObject.remove(options);
Arguments
options - (object) [Added in Actionaz 3.0.1.]
noErrorDialog - (bool) should an error dialog be shown if an error occurs (Windows only, default: true)
noConfirmDialog - (bool) should a confirmation dialog be shown if needed (Windows only, default: true)
noProgressDialog - (bool) should a progress dialog be shown (Windows only, default: true)
allowUndo - (bool) should the file/directory be moved to the trash bin (Windows only, default: false)
Returns
Exceptions
(ParameterCountError) incorrect parameter count
(RemoveError) remove failed
(RemoveAbortedError) remove aborted (Windows only)
Enumerations
OpenMode
Values
ReadOnly: file opened for reading only
WriteOnly: file opened for writing only
ReadWrite: file opened for reading and writing
Append: file opened for writing at the end of the file
Truncate: file opened for writing, erases any previous content
Text: file opened in text mode
Unbuffered: file opened in unbuffered mode
Notes
This is a flag enumeration, that means that you can use multiple values using the | operator.
Example:
myObject.open("myfile.txt", File.WriteOnly | File.Append | File.Text);