Weird string-parsing prob with filename

this is my first foray into PHP file stuff… (but I think it’s actually a string-parsing prob, not a file problem…)

inside a dir., I need to find all files that are a dir…
so going from example here,

I did:

if (is_dir($dirPgs)) {
    if ($dh = opendir($dirPgs)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dirPgs . $file) . "<br>";
            
            //    but prob here is it also pulls in parent dir and g'parent dir (weird...)
            //    so: what I need is all dirs, and they're all named "page1", "page2", etc..
            //    so I thought I'd just check for occurrence of string "page" in file name..
            //    and ran into a heap of trouble.. as this
                if ( strpos($file, 'page') == true) echo 'this is a page dir';
            //    is not doing what I expect it to.... it's not printing anything...
            //    there are six dirs, from "page1" to "page6" in this particular instance..
            //    so why is my 'echo' stmt here not printing?
            
            //    weird thing is, if I do
            if ( strpos($file, 'age') == true) echo 'this is a page dir';
            // then 'echo' stmt prints...  WHY ON EARTH IS THIS??
        }
        closedir($dh);
    }
}

this is just bizarre… I have checked file-names like this with Java a lot, with the IndexOf() string method, always works as expected… I just don’t get what’s happening here… what am I missing…

thank you…

Zero does not == true

http://php.net/manual/en/function.strpos.php

Might i suggest [FPHP]glob[/FPHP] instead, considering it has a flag called GLOB_ONLYDIR?

ok, will try that… thank you… so how do I filter out parent & g’parent dirs? this is a pain… never had to deal w/that with Java…

eventually will need to do more complex file-name checking… this is how I do it in Java:

public boolean checkPhotoName(String photoName) {
        String ValidChars = "0123456789.";
        String photoNameSub = "";
        char oneChar;
        
        if (photoName.startsWith("0")) { return false; }    
    //    if (photoName.indexOf("0") == 0) {return false; }
    
        if (photoName.indexOf(".") == -1) { 
            return false; 
        } else {    
            photoNameSub = photoName.substring(0,photoName.indexOf("."));
        }
        if (photoNameSub.length() > 2 )      { return false; }
        
        if (photoName.indexOf(".jpg") == -1) { return false; }    
        
        for (int i = 0; i < photoNameSub.length(); i++) { 
            oneChar = photoNameSub.charAt(i); 
            if (ValidChars.indexOf(oneChar) == -1)  {
                return false; 
            }
        }
        return true;
    }

thank you…

Glob should not return parent directories if you structure the glob correctly…as far as validating the filename…

if(!preg_match("~^\d{1,2}\.jpg$~",$photoname)) { return false; }

“If the entirety of the string in $photoname does not consist purely of 1 or 2 digits followed by “.jpg”, return false.”

EDIT: Sorry, you wanted to exclude things that start with 0.

if(!preg_match("~^[1-9]\d?\.jpg$~",$photoname)) { return false; }

I don’t know what glob() is returning… it’s not doing anything for me…

I’m starting another thread… am having a really hard time with this…

thank you…