Connecting Tech Pros Worldwide Help | Site Map

Negate glob() pattern

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 16th, 2008, 09:35 PM
Franz Marksteiner
Guest
 
Posts: n/a
Default 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


  #2  
Old March 16th, 2008, 09:55 PM
petersprc
Guest
 
Posts: n/a
Default 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("Command \"$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:
Quote:
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
  #3  
Old March 17th, 2008, 09:25 AM
Franz Marksteiner
Guest
 
Posts: n/a
Default Re: Negate glob() pattern

petersprc wrote:
Quote:
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.
Quote:
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?
Quote:
On Mar 16, 5:31 pm, "Franz Marksteiner" <franzmarkstei...@gmail.com>
wrote:
Quote:
>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

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.