|
exists() returns if the specified file exists or not.
|
ls() displays the files in the specified directory. If directory is not specified, the directory ${user.dir} is implicitly used.
|
chdir() changes the current directory (the property "user.dir") to the specified directory.
|
pwd() displays the current directory (the property "user.dir").
|
mkdir() makes a directory.
|
renameTo() changes the name of the file old to new.
|
delete() deletes the specified file. If the file is a directory and it is not empty, the directory is deleted only when recursive is true.
|
find() traverses a directory tree recursively. If action is specified, it should return a boolean value. action is applied to each file (and directory) under the directory with an extra argument, as long as it returns true.
action(File file, Object extra)
For example, the following example shows how to delete "*~" files under the current directory.
find(".", function (f, a) {if (f.getName().endsWith("~")) delete(f); true})
If action is not specified, each file is printed on the output stream of the current context.
When recalc is specified and non-null, the extra argument is re-calculated by the function, applying to each file and the argument extra.
extra = recalc(File file, Object extra)
For example, the following example prints file names with indents to show the structure of the directory.
function printTree(base){ find(base, function (f, extra) {println(extra + f.getName()); true}, "", function (f, extra) extra + " ") }
|
If source is a directory, copy() copies all files under the source directory to destination directory. If source is a ordinary file and destination is a directory, copy() copies the file to destination directory. If both source and destination are ordinary files, copy() copies the content of the source file to the destination file.
|
cat() displays the content of file or files. If output is specified, the content is written to the output.
|
zcat() decompress the content of file and displays. If outputStream is specified, data is written to the stream. Otherwise, it returns a java.io.PipedInputStream object which can be read with read() function.
The following example illustrates how to load a gzip-compressed script.
load(zcat("big.pnut.gz"))
|
gzip() compress the content of fileName or input . If output is specified, data is written into the stream. Otherwise, it returns a java.io.PipedInputStream object which can be read with read() function.
createTempFile() creates a new empty file in the specified directory, using given prefix and suffix to generate its name. In Java2, the created file is deleted when the virtual machine terminates normally.
|
shellExpand() searches files whose names match the pattern and returns an Enumeration object from which the matched files can be retrieved.
This function depends on the pnuts::regex module.
shellExpand("*/*/*pnut")