Tests for the existance of the file.
This is an exact duplicate of the -e function.
Tests whether filename is a file.
This is an exact duplicate of the -f function.
Test whether filename is a directory.
This is an exact duplicate of the -d function.
Does the file or directory exist, and can we read from it.
Does the file or directory exist, and can we write to it
<B>ORB> can we create the file or directory.
Does a file or directory exist, and can we both read and write it.
Does a file or directory exist, and can we execute it.
Is this something we can open a filehandle to. Returns true if filename
exists, is a file, and we can read from it.
Can we remove the file or directory.
Does the file filename exist, and is it a text file.
Does the file filename exist, and is it a binary file.
If the file exists, returns its size in bytes.
Returns undef if the file does not exist.
open [ CW$mode, ] CW$filename
Rough analogue of the open function, but creates directories on demand
as needed. Supports most of the normal options to the normal open function.
In the single argument form, it takes modes in the form [mode]filename. For
example, all the following are valid.
File::Flat->open( filename );
File::Flat->open( <filename );
File::Flat->open( >filename );
File::Flat->open( >>filename );
File::Flat->open( +<filename );
In the two argument form, it takes the following
File::Flat->open( <, filename );
File::Flat->open( >, filename );
File::Flat->open( >>, filename );
File::Flat->open( +<, filename );
It does not support the more esoteric forms of open, such us opening to a pipe
or other such things.
On successfully opening the file, it returns it as an IO::File object.
Returns undef on error.
The same as File::Flat->open( <, filename )
The same as File::Flat->open( >, filename )
The same as File::Flat->open( >>, filename )
The same as File::Flat->open( +<, filename )
Opens and reads in an entire file, chomping as needed.
In array context, it returns an array containing each line of the file.
In scalar context, it returns a reference to an array containing each line of
the file. It returns undef on error.
The slurp method slurps a file in. That is it attempts to read the entire
file into a variable in as quick and memory efficient method as possible.
On success, returns a reference to a scalar, containing the entire file.
Returns undef on error.
write CW$filename, ( CW$content | \$content | \@content )
The write method is the main method for writing content to a file.
It takes two arguments, the location to write to, and the content to write,
in several forms.
If the file already exists, it will be clobered before writing starts.
If the file doesnt exists, the file and any directories will be created as
Content can be provided in three forms. The contents of a scalar argument will
be written directly to the file. You can optionally pass a reference to the
scalar. This is recommended when the file size is bigger than a few thousand
characters, is it does not duplicate the file contents in memory.
Alternatively, you can pass the content as a reference to an array containing
the contents. To ensure uniformity, write will add a newline to each line,
replacing any existing newline as needed.
Returns true on success, and undef on error.
append CW$filename, ( CW$content | \$content | \@content )
This method is the same as write, except that it appends to the end of
an existing file ( or creates the file as needed ).
This is the method you should be using to write to log files, etc.
overwrite CW$filename, ( CW$content | \$content | \@content )
Performs an atomic write over a file. It does this by writing to a temporary
file, and moving the completed file over the top of the existing file ( or
creating a new file as needed ). When writing to a file that is on the same
partition as /tmp, this should always be atomic.
This method otherwise acts the same as write.
copy CW$source, CW$target
The copy method attempts to copy a file or directory from the source to
the target. New directories to contain the target will be created as needed.
For example <File::Flat-( ./this, ./a/b/c/d/that );>> will create the
directory structure required as needed.
In the file copy case, if the target already exists, and is a writable file,
we replace the existing file, retaining file mode and owners. If the target
is a directory, we do NOT copy into that directory, unlike with the cp
unix command. And error is instead returned.
copy will also do limited recursive copying or directories. If source
is a directory, and target does not exists, a recursive copy of source will
be made to target. If target already exists ( file or directory ), copy
will returns with an error.
move CW$source, CW$target
The move method follows the conventions of the mv command, with the
exception that the directories containing target will of course be created
remove CW$filename [, CW$prune ]
The remove method will remove a file, or recursively remove a directory.
If a second (true) argument is provided, then once the file or directory
has been deleted, the method will the automatically work its way upwards
pruning (deleting) empty and thus assumably useless directories.
Returns true if the deletion (and pruning if requested) was a success, or
For a file that has already been delete, prune will work upwards,
removing any empty directories it finds.
For anyone familiar with CVS, it is similar to the update -P flag.
Returns true, or undef on error.
truncate CW$filename [, CW$size ]
The truncate method will truncate an existing file to partular size.
A size of 0 ( zero ) is used if no size is provided. If the file does not
exists, it will be created, and set to 0. Attempting to truncate a
directory will fail.
Returns true on success, or undef on error.
makeDirectory CW$directory [, mode ]
In the case where you do actually have to create a directory only, the
makeDirectory method can be used to create a directory or any depth.
An optional file mode ( default 0755 ) can be provided.
Returns true on success, returns undef on error.