Negate glob() pattern

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franz Marksteiner

    Negate glob() pattern

    Hi folks,

    is there a way to negate a glob() pattern?
    What I want is to get a tree structure, e.g. all .php files *and* all
    directories.
    How would I start here?

    --
    Freundliche Grüße,
    Franz Marksteiner

  • petersprc

    #2
    Re: Negate glob() pattern

    Hi,

    The find command can search within a directory tree:

    $dir = dirname(__FILE_ _);
    $cmd = 'find ' . escapeshellarg( $dir) . ' -name "*.php" ' .
    '-o -type d 2>&1';
    exec($cmd, $output, $exitCode);
    if ($exitCode != 0) {
    throw new Exception("Comm and \"$cmd\" failed with " .
    "exit code $exitCode: " . join("\n", $output));
    }
    echo "Found " . count($output) . " entries.<br>\n" ;

    As for glob, you can just call it multiple times: once with *.php and
    once with the GLOB_ONLYDIR flag.

    You could also use opendir/readdir.

    On Mar 16, 5:31 pm, "Franz Marksteiner" <franzmarkstei. ..@gmail.com>
    wrote:
    Hi folks,
    >
    is there a way to negate a glob() pattern?
    What I want is to get a tree structure, e.g. all .php files *and* all
    directories.
    How would I start here?
    >
    --
    Freundliche Grüße,
    Franz Marksteiner

    Comment

    • Franz Marksteiner

      #3
      Re: Negate glob() pattern

      petersprc wrote:
      As for glob, you can just call it multiple times: once with *.php and
      once with the GLOB_ONLYDIR flag.
      Yeah, I guess that makes sense.
      You could also use opendir/readdir.
      The thing is that glob seems to be way easier with the pattern
      functionality.
      In the past I did use opendir.

      What would you prefer?
      On Mar 16, 5:31 pm, "Franz Marksteiner" <franzmarkstei. ..@gmail.com>
      wrote:
      >Hi folks,
      >>
      >is there a way to negate a glob() pattern?
      >What I want is to get a tree structure, e.g. all .php files *and* all
      >directories.
      >How would I start here?
      >>
      >--
      >Freundliche Grüße,
      >Franz Marksteiner
      --
      Freundliche Grüße,
      Franz Marksteiner

      Comment

      Working...