Jump to content


Photo

excluding files with "-" in them


  • Please log in to reply
2 replies to this topic

#1 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 04 April 2006 - 07:34 PM

im trying to only include files from a certain directory that dont include "-" in the filename.

so:

opendir($dir);
$files = readdir($dir);
closedir($dir);

How do I say "except '-' "? I dont know where to start.

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 04 April 2006 - 07:44 PM

try something like this:

<?php
if ($handle = opendir($pathToFiles)) {

  while (false !== ($file = readdir($handle))) {
    if (!preg_match('|-|', $file)) {
      // there is no '-' in the name
      include("$pathToFiles/$file");
    }
  }
  closedir($handle);
}
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 Twentyoneth

Twentyoneth
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationGlasgow, KY

Posted 04 April 2006 - 07:50 PM

Perfect, works exactly how I need it to, thanks a ton!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users