feyd wrote:Where are you using it? More code maybe?
Try removing the last question mark in my regex.
Code: Select all
function _file_glob($path, $re_pattern)
{
$arr_names = array(); // Array of file/folder paths which meet glob criteria
if(is_dir($path)){
if($dh = opendir($path)){
clearstatcache();
while(($name = readdir($dh)) !== false){
if($name != '.' && $name != '..'){
//
// Check file/folder name against a regex pattern
//echo $name.'<br>';
if(preg_match($re_pattern, $name)){
// ...
}
I am aware of
glob() but my function goes way above and beyond the capabilities of
glob() thus the custom function.
I'm positive the problem lies with regex...
What I have concluded is that I need a function which:
1) Matches a directory name or file name (minus extension)
2) And
optionally matches an extension(s) list in brackets (php|gif) by starting at the END of the string and counting backwards (if possible?)
This way ANY file or folder is matched ALWAYS and optionally matching extensions...
S*ite...I just realized maybe the problem lies within my function....because I don't distinguish between file/folders in my code before matching...a path is a path is a path...

you know what I'm saying?
So using regex that i've describe above....it would return folders named 'myimages.gif' as well as files with GIF extensions...
Ok, so a re-write is in order
Having been exposed to my snippet of code above, can you think of a effective way of solving this problem?
I could check
$path.'/'.$name for it's type I suppose and use a different preg_match pattern (for file or folder) but then wouldn't that require me passing in two different patterns?
I want to avoid calling the function twice or passing seperate patterns if possible...
Cheers
