CommonFunctions::gdc PHP Method

gdc() public static method

reads a directory and return the name of the files and directorys in it
public static gdc ( string $strPath, boolean $booErrorRep = true ) : array
$strPath string path of the directory which should be read
$booErrorRep boolean en- or disables the reporting of errors which should be logged
return array content of the directory excluding . and ..
    public static function gdc($strPath, $booErrorRep = true)
    {
        $arrDirectoryContent = array();
        $error = PSI_Error::singleton();
        if (is_dir($strPath)) {
            if ($handle = opendir($strPath)) {
                while (($strFile = readdir($handle)) !== false) {
                    if ($strFile != "." && $strFile != "..") {
                        $arrDirectoryContent[] = $strFile;
                    }
                }
                closedir($handle);
            } else {
                if ($booErrorRep) {
                    $error->addError('opendir(' . $strPath . ')', 'directory can not be read by phpsysinfo');
                }
            }
        } else {
            if ($booErrorRep) {
                $error->addError('is_dir(' . $strPath . ')', 'directory does not exist on your machine');
            }
        }
        return $arrDirectoryContent;
    }

Usage Example

 /**
  * IDE devices
  *
  * @return void
  */
 private function _ide()
 {
     $bufd = CommonFunctions::gdc('/proc/ide', false);
     foreach ($bufd as $file) {
         if (preg_match('/^hd/', $file)) {
             $dev = new HWDevice();
             $dev->setName(trim($file));
             if (CommonFunctions::rfts("/proc/ide/" . $file . "/media", $buf, 1)) {
                 if (trim($buf) == 'disk') {
                     if (CommonFunctions::rfts("/proc/ide/" . $file . "/capacity", $buf, 1, 4096, false) || CommonFunctions::rfts("/sys/block/" . $file . "/size", $buf, 1, 4096, false)) {
                         $dev->setCapacity(trim($buf) * 512 / 1024);
                     }
                 }
             }
             if (CommonFunctions::rfts("/proc/ide/" . $file . "/model", $buf, 1)) {
                 $dev->setName($dev->getName() . ": " . trim($buf));
             }
             $this->sys->setIdeDevices($dev);
         }
     }
 }
All Usage Examples Of CommonFunctions::gdc