Static/PhpInclude/FareOfficeLib/General/Files.php File Reference

Functions that manipulates with the file system. More...

Go to the source code of this file.

Functions

 fileList ($directory_, $type_= 'ALL', $recursive_=true, $sort_=true)
 List all entities in one directory.


Detailed Description

Functions that manipulates with the file system.

Author:
Daniel Lindh <[email protected]>

Definition in file Files.php.


Function Documentation

fileList ( directory_,
type_ = 'ALL',
recursive_ = true,
sort_ = true 
)

List all entities in one directory.

Parameters:
$directory_ - string - The directory to list files from. Doesn't matter if it ends with / or not. Ie. /var/www
$type_ - string - Can be [ALL|FILE|DIR], defines which type of entities to list. FILE - List files in directory. DIR - List directories in directory. ALL - List both FILE and DIR
$recursive_ - boolean - Go through all directories recursively.
$sort_ - boolean - Sort all the result.
Returns:
array listOffiles List of all the files, not the directories. listOffiles[] = '/opt/RootLive/Sites/HtDocs/Admin/Admin.php'; listOffiles[] = '/opt/RootLive/Sites/Phpinc/Content/Content.php';

Definition at line 35 of file Files.php.

Referenced by Config::getSites().

00036 {
00037   // @todo add assertlog here
00038   // assertLog($type_ == 'ALL' || $type_ == 'FILE' || $type_ == 'DIR' , EL_LEVEL_3, ECAT_DIAGNOSTIC, 'fileList invalid type: ' . $type_);
00039 
00040   $directory_ = rtrim($directory_, '/') . '/';
00041   $type_ = strtoupper($type_);
00042 
00043   $result = array();
00044   if(is_dir($directory_))
00045   {
00046     $thisDir = dir($directory_);
00047 
00048     while(!empty($thisDir) && $entry = $thisDir->read())
00049     {
00050       if (($entry != '.') && ($entry != '..'))
00051       {
00052         $path = $directory_.$entry;
00053         if (is_file($path) && ($type_ == 'ALL' || $type_ == 'FILE'))
00054         {
00055           $result[] = $path;
00056         }
00057         elseif (is_dir($path))
00058         {
00059           if (($type_ == 'ALL' || $type_ == 'DIR'))
00060           {
00061             $result[] = $path;
00062           }
00063 
00064           if ($recursive_)
00065           {
00066             $result = array_merge($result, fileList($path, $type_, true, false));
00067           }
00068         }
00069       }
00070     }
00071   }
00072 
00073   if (!empty($result) && $sort_)
00074   {
00075     asort($result);
00076   }
00077 
00078   return $result;
00079 }


Generated on Wed May 6 23:28:24 2009 for fareofficelib by  doxygen 1.5.8