|
PTools::SDF::DIR - Load dir entries into an 'PTools::SDF::SDF' object |
PTools::SDF::DIR - Load dir entries into an 'PTools::SDF::SDF' object
This document describes version 0.11, released February, 2006.
This class depends directly on the PTools::SDF::SDF class.
Load the contentes of a subdirectory into an object of this class.
use PTools::SDF::DIR;
or use PTools::SDF::DIR ("stat");
$dirObj = new PTools::SDF::DIR( "/subdir/path" );
Obtain information about the subdirectory's entries.
$dirname = $dirObj->ctrl('fileName');
print " Contents of $dirname:\n";
foreach my $idx ( 0 .. $dirObj->param() ) {
$filename = $dirObj->param( $idx, 'filename' );
$fileBase = $dirObj->param( $idx, 'file' );
$fileExt = $dirObj->param( $idx, 'ext' );
if ( $dirObj->isaFile( $idx ) ) {
$size = $dirObj->stat_size( $idx );
$atime = $dirObj->stat_atime( $idx );
print " $filename is a FILE, size=$size, atime=$atime\n";
} elsif ( $dirObj->isaDir( $idx ) ) {
$uid = $dirObj->stat_uid( $idx );
$mode = $dirObj->stat_mode( $idx );
print " $filename is a DIR, uid=$uid, mode=$mode\n";
} else {
$type = $dirObj->type( $idx );
$dev = $dirObj->stat_dev( $idx );
print " $filename type is $type, on dev=$dev\n";
}
}
However, this class is influenced by the use directive. If a ``stat'' parameter is added, a stat(2) is performed on each entry in a directory as it is loaded into an object of this class.
The default is to skip the 'stat' calls while loading the directory entries. This is for performance reasons. In this case, a 'stat' is not called on a particular entry until a method is invoked that needs to return some or all of the stat data for that entry.
In either case, only one 'stat' call is made per entry during the life of a given object of this class.
Examples:
Delay ``stat'' calls on dir entries until they are actually needed.
use PTools::SDF::DIR;
$dirObj = new PTools::SDF::DIR( "/subdir/path" );
Alternatively, call ``stat'' on every dir entry during object creation.
use PTools::SDF::DIR ("stat");
$dirObj = new PTools::SDF::DIR( "/subdir/path" );
This class inherits from the PTools::SDF::SDF class which, in turn, inherits from the PTools::SDF::File class. Many other methods exist in these classes for accessing, sorting, locking and manipulating the contents of objects of this class.
In addition, several methods exist in this class to facilitate obtaining information about entries in a given subdirectory.
The following methods provide access to file type information for any directory entries contained in the current object.
The type returned will be one of the following.
file - vanilla file dir - directory symlink - symbolic link socket - socket pipe - named pipe other - other / unknown
Example:
$filename = $dirObj->param( $idx, 'filename' );
if ( $dirObj->isaFile( $idx ) ) {
print " $filename is a FILE\n";
} elsif ( $dirObj->isaDir( $idx ) ) {
print " $filename is a DIR\n";
} else {
$type = $dirObj->type( $idx );
print " $filename is a $type\n";
}
The following methods provide access to status information for any directory entries contained in the current object.
For performance reasons, no 'stat' is performed on a given directory entry until a method is invoked that accesses stat data for that particular entry. Once obtained, the 'stat' data is cached so there is no further performance penalty for requesting additional 'stat' data for that particular directory entry.
To stat every directory entry while the entries are loaded during object creation, see the Constructor section, above.
The RecIdx is the record index into the current object of directory entries and StatIdx is the offset into the 'stat(2)' array.
Example:
# In this example each of the three 'fileSize' variables are equivalent.
$dirRef = new PTools::SDF::DIR("/tmp");
$statIdx = 7;
foreach $recIdx ( 0 .. $dirRef->param() ) {
(@statArray)= $dirRef->stat_array( $recIdx );
$fileSizeA = $dirRef->statFile( $recIdx, $statIdx );
$fileSizeB = $dirRef->stat_size( $recIdx );
$fileSizeC = $statArray[ $statIdx ];
}
Examples:
(@statArray)= $dirRef->stat_array( $recIdx );
$fileSize = $dirRef->stat_size( $recIdx );
$fileInode = $dirRef->stat_ino( $recIdx );
This PTools::SDF::DIR class inherits from the PTools::SDF::SDF and PTools::SDF::File classes. Additional methods are available via these parent classes.
See the PTools::SDF::Overview manpage, the PTools::SDF::ARRAY manpage, the PTools::SDF::CSV manpage, the PTools::SDF::DB manpage, the PTools::SDF::DSET manpage, the PTools::SDF::File manpage, the PTools::SDF::IDX manpage, the PTools::SDF::INI manpage, the PTools::SDF::SDF manpage, the PTools::SDF::TAG manpage, the PTools::SDF::Lock::Advisory manpage, the PTools::SDF::Sort::Bubble manpage, the PTools::SDF::Sort::Quick manpage and the PTools::SDF::Sort::Shell manpage.
Chris Cobb, <nospamplease@ccobb.net>
Copyright (c) 1997-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
PTools::SDF::DIR - Load dir entries into an 'PTools::SDF::SDF' object |