0

This script includes multiple files from a directory, how can I leave out a single file from the inclusion, for example, file one.php to leave out the included directory

And here's the script

<?php      
$dir = "dir1/dir2/dir3/dir4 ";
$phpfiles  = glob($dir ."*.php");
$phpfiles=array_map(function($f){return pathinfo($f, PATHINFO_FILENAME );},$phpfiles);
foreach ($phpfi2les as $phpfile){
echo '<li><a href="'.'/'.$dir.$phpfile.'/'.'">'.$phpfile.'</a></li>';
 }
?>

example output

1
2
3
omit the file 3
user2988099
  • 1
  • 1
  • 7

2 Answers2

0

Several ways. Here's one if you can remove it from the array:

$phpfiles = preg_grep("/one.php$/", glob($dir . "*.php"), PREG_GREP_INVERT);

If you wanted to exclude multiple files:

$exclude = array('one.php', 'two.php');
$phpfiles = preg_grep("/(" . implode("|", $exclude) . ")$/", glob($dir . "*.php"), PREG_GREP_INVERT);
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
0

Quick/dirty check for a single file to skip:

foreach ($phpfiles as $phpfile) {
   if (basename($phpfile) == 'file to be skipped') {
      continue;
   }
}
AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
Marc B
  • 356,200
  • 43
  • 426
  • 500