File::Util - Easy, versatile, portable file handling
This is a developer's release, and is not intended for use in the public sector. This code is made available for developers who wish to aid in the furthering of the code, though it _is_ stable.
This is not a registered module in the CPAN module list. It is not part of the CPAN yet.
-- This part of the documentation is not yet complete! --
Nothing here at present.
File::Util provides a comprehensive toolbox of utilities to automate all kinds of common tasks on file / directories. Its purpose is to do so in the most portable manner possible so that users of this module won't have to worry about whether their programs will work on other OSes and machines.
To install this module type the following at the command prompt:
perl Makefile.PL make make test make install
On windows machines use nmake rather than make; those running cygwin don't have to worry about this. If you don't know what cygwin is, use nmake and check out http://cygwin.com/ after you're done installing this module if you want to find out.
Note: Some of the methods listed will state that they are autoloaded methods. Autloaded methods are not compiled at runtime as part of your process and only get created if called somewhere in your program. (see AutoLoader.)
bitmask
bitmask( [file name] )
Gets the bitmask of the named file, provided the file exists. If the file exists, the bitmask of the named file is returned in four digit octal notation eg- 0644. Otherwise, returns undef if the file does not exist. This is an autoloaded method.
0644
undef
can_flock
Returns 1 if the current system claims to support flock() and if the Perl process can successfully call it. (see "flock" in perlfunc.) Unless both of these conditions are true a zero value (0) is returned. This is an autoloaded method. This is a constant subroutine. It accepts no arguments and will always return the same value for the system on which it is executed.
flock()
Note: Perl will try to support or emulate flock whenever it can via available system calls, namely flock; lockf; or with fcntl.
flock
lockf
fcntl
can_read
can_read( [file name] )
Returns 1 if the named file (or directory) is readable by your program according to the applied permissions of the file system on which the file resides. Otherwise a value of undef is returned.
This works the same as Perl's built-in -r file test operator, (see "-X" in perlfunc), it's just easier for some people to remember. This is an autoloaded method.
-r
can_write
can_write( [file name] )
Returns 1 if the named file (or directory) is writable by your program according to the applied permissions of the file system on which the file resides. Otherwise a value of undef is returned.
This works the same as Perl's built-in -w file test operator, (see "-X" in perlfunc), it's just easier for some people to remember. This is an autoloaded method.
-w
created
created( [file name] )
Returns the time of creation for the named file in non-leap seconds since whatever your system considers to be the epoch. Suitable for feeding to Perl's built-in functions "gmtime" and "localtime". (see "time" in perlfunc.) This is an autoloaded method.
ebcdic
Returns 1 if the machine on which the code is running uses EBCDIC, or returns 0 if not. (see perlebcdic.) This is an autoloaded method. This is a constant subroutine. It accepts no arguments and will always return the same value for the system on which it is executed.
escape_filename
escape_filename( [string] )
-- Documentation for this method is not yet complete! -- This is an autoloaded method.
existent
existent( [file name] )
Returns 1 if the named file (or directory) exists. Otherwise a value of undef is returned.
This works the same as Perl's built-in -e file test operator, (see "-X" in perlfunc), it's just easier for some people to remember. This is an autoloaded method.
-e
file_type
file_type( [file name] )
Returns a list of keywords corresponding to each of Perl's built in file tests (those specific to file types) for which the named file returns true. (see "-X" in perlfunc.) This is an autoloaded method.
The keywords and their definitions appear below; the order of keywords returned is the same as the order in which the are listed here:
File is a plain file.
File is a text file.
File is a binary file.
File is a directory.
File is a symbolic link.
File is a named pipe (FIFO).
File is a socket.
File is a block special file.
File is a character special file.
flock_rules
flock_rules( [Keywords] )
isbin
isbin( [file name] )
Returns 1 if the named file (or directory) exists. Otherwise a value of undef is returned, indicating that the named file either does not exist or is of another file type.
This works the same as Perl's built-in -B file test operator, (see "-X" in perlfunc), it's just easier for some people to remember. This is an autoloaded method.
-B
last_access
last_access( [file name] )
Returns the last accessed time for the named file in non-leap seconds since whatever your system considers to be the epoch. Suitable for feeding to Perl's built-in functions "gmtime" and "localtime". (see "time" in perlfunc.) This is an autoloaded method.
last_mod
last_mod( [file name] )
Returns the last modified time for the named file in non-leap seconds since whatever your system considers to be the epoch. Suitable for feeding to Perl's built-in functions "gmtime" and "localtime". (see "time" in perlfunc.) This is an autoloaded method.
line_count
line_count( [file name] )
Returns the number of lines in the named file. Fails with an error if the named file does not exist.
list_dir
list_dir( [directory name] , [--opts] )
-- Documentation for this method is not yet complete! --
load_dir
load_dir( [directory name] , [--ds-type] )
Returns a data structure containing the contents of each file present in the named directory. This is an autoloaded method.
The type of data structure returned is determined by the optional data-type switch. Only one option may be used for a given call to this method. Recognized options are listed below.
--as-list
Causes the method to return a list comprised of the contents loaded from each file (in case-sensitive order) located in the named directory.
--as-listref
Same as above, except an array reference to the list of items is returned rather than the list itself.
--as-hashref
Implicit. If no option is passed in, the default behavior is to return a reference to an anonymous hash whose keys are the names of each file in the specified directory; the hash values for contain the contents of the file represented by its corresponding key.
Note: This method does not distinguish between plain files and other file types such as binaries, FIFOs, sockets, etc.
Restrictions imposed by the current "read limit" (see the readlimit()) entry below will be applied to the files opened by this method as well. Adjust the readlimit as necessary.
my($files) = $fu->load_dir('directory/to/load/');
The above code creates an anonymous hash reference that is stored in the variable named "$files". The keys and values of the hash referenced by "$files" would resemble those of the following code snippet (given that the files in the named directory were the files 'a.txt', 'b.html', 'c.dat', and 'd.conf')
$files
my($files) = { 'a.txt' => "the contents of file a.txt", 'b.html' => "the contents of file b.html", 'c.dat' => "the contents of file c.dat", 'd.conf' => "the contents of file d.conf", };
load_file
load_file( [file name] , [--opts] )
make_dir
make_dir( [new directory name] , [--opts] )
max_dives
max_dives( [integer] )
needs_binmode
Returns 1 if the machine on which the code is running requires that binmode() (a built-in function) be called on open file handles, or returns 0 if not. (see "binmode" in perlfunc.) This is an autoloaded method. This is a constant subroutine. It accepts no arguments and will always return the same value for the system on which it is executed.
binmode()
new
new( [--opts] )
open_handle
open_handle( [file name] , [--opts] )
readlimit
readlimit( [integer] )
size
size( [file name] )
strip_path
strip_path( [string] )
trunc
trunc( [file name] )
use_flock
use_flock( [true / false value] )
write_file
write_file('file' =
valid_filename
valid_filename( [string] )
NL
SL
None by default.
@Class::OOorNO::EXPORT_OK
:all (exports all of @File::Util::EXPORT_OK)
None at present.
This documentation isn't done yet, as you can see. This is being rectified as quickly as possible. Please exercise caution if you choose to use this code before it can be further documented for you. Please excuse the inconvenience.
Tommy Butler <cpan@atrixnet.com>
Copyright(C) 2001-2003, Tommy Butler. All rights reserved.
This library is free software, you may redistribute and/or modify it under the same terms as Perl itself.
To install File::Util, copy and paste the appropriate command in to your terminal.
cpanm
cpanm File::Util
CPAN shell
perl -MCPAN -e shell install File::Util
For more information on module installation, please visit the detailed CPAN module installation guide.