Module ringo/file
Default properties and methods of the File prototype.
Constructor for File objects, providing read and
write access to the file system.
Parameters
| String|java.io.File |
path |
as String, can be either absolute or relative
to the ringo home directory |
Create a new empty temporary file in the default temporary-file directory.
Parameters
| String |
prefix |
the prefix of the temporary file; must be at least three characters long |
| String |
suffix |
the suffix of the temporary file; may be null |
Define iterator to loop through the lines of the file for ordinary files,
or the names of contained files for directories.
for each (var line in file) ...
for each (var filename in dir) ...
File.prototype.canRead
()
Tests whether the application can read the file
represented by this File object.
Returns
| Boolean |
Boolean true if the file exists and can be read; false otherwise |
File.prototype.canWrite
()
Tests whether the file represented by this File object is writable.
Returns
| Boolean |
Boolean true if the file exists and can be modified; false otherwise. |
File.prototype.close
()
Closes the file represented by this File object.
File.prototype.createTempFile
(prefix, suffix)
Create a new empty temporary file in the this directory, or in the directory
containing this file.
Parameters
| String |
prefix |
the prefix of the temporary file; must be at least three characters long |
| String |
suffix |
the suffix of the temporary file; may be null |
File.prototype.eof
()
Returns true if the file represented by this File object
has been read entirely and the end of file has been reached.
File.prototype.exists
()
Tests whether the file or directory represented by this File object exists.
Returns
| Boolean |
Boolean true if the file or directory exists; false otherwise |
File.prototype.flush
()
Purges the content of the file represented by this File object.
Returns the absolute pathname string of this file.
If this File object's pathname is already absolute, then the pathname
string is simply returned as if by the getPath() method. If this
abstract pathname is the empty abstract pathname then the pathname
string of the current user directory, which is named by the system
property user.dir, is returned. Otherwise this pathname is resolved
in a system-dependent way. On UNIX systems, a relative pathname is
made absolute by resolving it against the current user directory.
On Microsoft Windows systems, a relative pathname is made absolute
by resolving it against the current directory of the drive named by
the pathname, if any; if not, it is resolved against the current user
directory.
Returns
| String |
String The absolute pathname string |
Returns the length of the file represented by this File object.
The return value is unspecified if this pathname denotes a directory.
Returns
| Number |
Number The length, in bytes, of the file, or 0L if the file does not exist |
File.prototype.getName
()
Returns the name of the file or directory represented by this File object.
This is just the last name in the pathname's name sequence.
If the pathname's name sequence is empty, then the empty
string is returned.
Returns
| String |
String containing the name of the file or directory |
Returns the pathname string of this File object's parent directory.
Returns
| String |
String containing the pathname of the parent directory |
File.prototype.getPath
()
Returns the pathname string of this File object.
The resulting string uses the default name-separator character
to separate the names in the name sequence.
Returns
| String |
String of this file's pathname |
File.prototype.hardCopy
(dest)
Makes a copy of a file or directory, possibly over filesystem borders.
Parameters
| String|ringo.File |
dest |
as a File object or the String of
full path of the new file |
Tests whether this File object's pathname is absolute.
The definition of absolute pathname is system dependent.
On UNIX systems, a pathname is absolute if its prefix is "/".
On Microsoft Windows systems, a pathname is absolute if its prefix
is a drive specifier followed by "\", or if its prefix is "\".
Returns
| Boolean |
Boolean if this abstract pathname is absolute, false otherwise |
Tests whether the file represented by this File object is a directory.
Returns
| Boolean |
Boolean true if this File object is a directory and exists; false otherwise |
File.prototype.isFile
()
Tests whether the file represented by this File object is a normal file.
A file is normal if it is not a directory and, in addition, satisfies
other system-dependent criteria. Any non-directory file created by a
Java application is guaranteed to be a normal file.
Returns
| Boolean |
Boolean true if this File object is a normal file and exists; false otherwise |
File.prototype.isHidden
()
Tests whether the file represented by this File object is a hidden file.
What constitutes a hidden file may depend on the platform we are running on.
Returns
| Boolean |
Boolean true if this File object is hidden |
File.prototype.isOpen
()
Returns true if the file represented by this File object
is currently open.
Returns the time when the file represented by this File object was last modified.
A number representing the time the file was last modified,
measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970),
or 0L if the file does not exist or if an I/O error occurs.
Returns
| Number |
Number in milliseconds since 00:00:00 GMT, January 1, 1970 |
File.prototype.list
(pattern)
List of all files within the directory represented by this File object.
You may pass a RegExp Pattern to return just files matching this pattern.
Example: var xmlFiles = dir.list(/.*.xml/);
Parameters
| RegExp |
pattern |
as RegExp, optional pattern to test each file name against |
Returns
| Array |
Array the list of file names |
File.prototype.listFiles
(pattern)
List of all files within the directory represented by this File object.
You may pass a RegExp Pattern to return just files matching this pattern.
Example: var xmlFiles = dir.list(/.*.xml/);
Parameters
| RegExp |
pattern |
as RegExp, optional pattern to test each file name against |
Returns
| Array |
Array the list of File objects |
Recursivly lists all files below a given directory
you may pass a RegExp Pattern to return just
files matching this pattern.
Parameters
| RegExp |
pattern |
as RegExp, to test each file name against |
Returns
|
Array the list of absolute file paths |
Creates the directory represented by this File object.
Returns
| Boolean |
Boolean true if the directory was created; false otherwise |
File.prototype.move
(dest)
Moves a file to a new destination directory.
Parameters
| String |
dest |
as String, the full path of the new file |
Returns
|
Boolean true in case file could be moved, false otherwise |
File.prototype.open
(options)
Opens the file represented by this File object. If the file exists,
it is used for reading, otherwise it is opened for writing.
If the encoding argument is specified, it is used to read or write
the file. Otherwise, the platform's default encoding is used.
Parameters
| Object |
options |
an optional argument holder object.
The following options are supported:
- charset name of encoding to use for reading or writing
- append whether to append to the file if it exists
|
Returns
| Boolean |
Boolean true if the operation succeeded |
File.prototype.readAll
()
This methods reads all the lines contained in the
file and returns them.
Returns
| String |
String of all the lines in the file |
File.prototype.readln
()
This methods reads characters until an end of line/file is encountered
then returns the string for these characters (without any end of line
character).
Returns
| String |
String of the next unread line in the file |
File.prototype.remove
()
Deletes the file or directory represented by this File object.
This method removes a directory recursively .
DANGER! DANGER! HIGH VOLTAGE!
The directory is deleted recursively without
any warning or precautious measures.
File.prototype.renameTo
(toFile)
Renames the file represented by this File object.
Whether or not this method can move a file from one
filesystem to another is platform-dependent. The return
value should always be checked to make sure that the
rename operation was successful.
Parameters
| File |
toFile |
File object containing the new path |
Returns
| Boolean |
true if the renaming succeeded; false otherwise |
Returns file as ByteArray.
Useful for passing it to a function instead of an request object.
File.prototype.write
(what)
Appends a string to the file represented by this File object.
Parameters
| String |
what |
as String, to be written to the file |
See
File.prototype.writeln
(what)
Appends a string with a platform specific end of
line to the file represented by this File object.
Parameters
| String |
what |
as String, to be written to the file |
See