Jump to content

Archived

This topic is now archived and is closed to further replies.

Twentyoneth

excluding files with "-" in them

Recommended Posts

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.

Share this post


Link to post
Share on other sites
try something like this:

[code]
<?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);
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.