1

I'm having trouble finding an answer to this one.

What I need to achieve is to scan a directory with subdirectories to return a total file count where the character count of the filename is 48 characters in length.

So something like:

scan c:\blah for files but only return a result if the filename is 48 characters then add the total of all files found in c:\blah which would result in c:\blah having (example) 3 files

The filenames do not need to be shown, just to total number of files meeting this criteria.

2

1 Answer 1

0

Try this:

<?php

$length = 48;
$directory = 'C:/';

$total = 0;

foreach (new DirectoryIterator($directory) as $fn)
{
    if ($fn->isDir() && strlen($fn->getFilename()) == $length)
    {
        foreach (new DirectoryIterator($fn->getPathname()) as $sfn)
        {
            if (!$sfn->isDot())
                $total++;
        }
    }
}

echo $total;
2
  • You know what.. that's perfect, but I missed a very important note out - its on a remote server. Example \\thisserver\d$\another\folder\here
    – Rik
    Oct 19, 2012 at 7:42
  • Right, so I get that I can go remote once I have access.. but how to go sub sub directories? This (correct me if I'm wrong) only goes one deep.
    – Rik
    Oct 19, 2012 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.