Break if no file found in directory

Discussion in 'Programming' started by Peuplarchie, Nov 16, 2008.

  1. #1
    Good day to you,
    I have a function which return an array of files.
    I would need it to break if there is no file in the directory.

    Here is the code :
    function compileList($extensions)
    {
         if ($handle = opendir('.')) {
       while (false !== ($file = readdir($handle)))
          {
              $ext = strtolower(end(explode('.', $file)));
           
              if (in_array($ext, $extensions) AND $file != "." AND $file != "..")
                  {
                      $files[$file]=implode(file($file));
                  }
           }
      closedir($handle);
      }
      return $files;
             
    }
    PHP:
    Thanks !
     
    Peuplarchie, Nov 16, 2008 IP
  2. Peuplarchie

    Peuplarchie Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    if (empty($files))
    {
        echo 'No results';
        return null;
    }
    return
    
    PHP:
     
    Peuplarchie, Nov 16, 2008 IP