As for debugging, the first step is to make sure that $aItems has directories within it. Perform a print_r($aItems); or a var_dump to make sure it has items within it. Then check that $aItemsFiltered also has data. If $aItems has data and $aItemsFiltered does not, make sure that the filterArrayOnlyDirectories function is within scope as an array_filter without a valid callback will always return false (and therefore have 0 results in the end).

I'm betting you do not have the function, unless you've modified it. I'd have a syntax error on this line: if (is_dir($itm) && !in_array($itm, array('.', '..')) since I'm missing a closing ).

Edit:
Oh yeah I forgot that glob has an ONLYDIR directive! Wait, does that include the '.' and '..' as well?

how does one make sure that the filterArrayOnlyDirectories function is within scope?

cheers

10-05-2012, 05:37 PM

kbluhm

Quote:

Originally Posted by Fou-Lu

Edit:Oh yeah I forgot that glob has an ONLYDIR directive! Wait, does that include the '.' and '..' as well?

No, they are excluded. :)

10-05-2012, 05:45 PM

LJackson

thanks kbluhm your solution works :)

would still like to get your method working fou-lu always nice to see different approaches to a problem

thanks guys

10-05-2012, 06:12 PM

Fou-Lu

Nice. I've been using iterators for so long I've forgotten about some of these more basic ones. And the globiterator itself let .'s into it depending on the flags.

To make sure its within scope, you simply add it to this page to be accessible or to a file that is included into this one. Sounds like its not in scope though since the original code would have thrown a fatal error since it would have had a syntactical error. Functions are global so long as they are not nested and are not a part of a class or namespace. Conditional branches also dictate if functions are available, so don't put it in an if condition.

counts the folders/sub directories what d i need to change to make it count just the files within the directory not including any sub directories (not that there will be any) but files directly within the directory

many thanks
Luke

10-05-2012, 10:42 PM

Fou-Lu

There is no corresponding GLOB_ONLYFILE directive. However, so long as you have named extensions, then you can simply use a glob pattern of '/*.*'. If you don't have extensions, you'll need to make use of !is_dir.

Alternatively, you can pull a glob() of all records, and a glob of GLOB_ONLYDIR. Then you can use array_diff to remove the ones from the only directories glob from the entire glob which will leave you with only the files.
That should be doable as such (I can't test this where I am I'm afraid):