File operations class (still under progress)
Created by Jose Chafardet , last update on 30/10/2008 11:37
This is a small class i have been writing to perform several file operations. for now only list files on a single directory and the same but recursively. I will keep improving it and modifying this one here as I work on it.
//==================
// Define class name
class Fileops {
//===========
// Properties
var $path ;
var $farray ;
//===========================
// Public method get_filelist
// Gets a list of files (non recursive)
// contained on a given path
public function get_filelist ( $path ) {
$this ->path = $path . '/' ;
// get the array of values on the $path given, removing . and ..
$this ->farray = scandir( $this ->path ) ;
// for every value on the array $array, as $item, check if any is a directory
foreach ( $this ->farray as $item ) {
if ( ( $item != '.' ) && ( $item != '..' ) ) {
if ( is_file ( $this ->
path .
$item ) ) { $return_array [ ] = $item ;
} // end if
} // end if
} // end foreach
return $return_array ;
} // end public method get_filelist
//===========================
// Public method get_rfilelist
// like get_filelist, gets a list of files
// on a given path, but recursive.
function get_rfilelist
( $path , &
$return_array =
array ( ) ) { $this ->path = $path . '/' ;
// get the array of values on the $path given, removing . and ..
$array = scandir( $path ) ;
// for every value on the array $array, as $item, check if any is a directory
foreach ( $farray as $item ) {
if ( ( $item != '.' ) && ( $item != '..' ) ) {
if ( is_dir ( $this ->
path .
$item ) ) { $return_array [ ] = $item ;
$item = $this ->path . $item . "/" ;
$return_array = $this ->get_rfilelist ( $item , $return_array ) ;
}
else if ( is_file ( $this ->
path .
$item ) ) { $return_array [ ] = $item ;
}
}
}
return $return_array ;
}
} // end class
Dependencies
No special requirements are needed by this snippet
By logging in you will be able to:
Recommand this page to someone else
Monitor changes on this item
Rate this item
Post comments
Download this item
Login now!