如何使用RecursiveDirectoryIterator使用isDot()删除点?

I have this simple below code to help me get the contents of all files and sub folder. I took this code from the PHP cook book. it says that I can use the isDot() but it doesn't explain how to ..

I tried to put a if just before array but it doesn't work...

if (! $file->isDot())

I don't know how to put both getPathname and isDot when adding to the array.

I've read the PHP net website but don't understand how to fit in.

code:

$dir  =  new  RecursiveDirectoryIterator('/usr/local'); 

$dircontent = array();
foreach (new RecursiveIteratorIterator($dir) as $file) {

$dircontent [] = $file -> getPathname();

}
print_r($dircontent);

Use the FilesystemIterator::SKIP_DOTS flag in your RecursiveDirectoryIterator to get rid of dot files:

$dir    = '/usr/local';
$result = array();
$files  = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator(
        $dir,
        FilesystemIterator::SKIP_DOTS
    )
);


foreach ($files as $file) {
    $result[] = $file->getPathname();
}

print_r($result);

The reason isDot() is failing is that your $file variable holds a SplFileInfo object, not a DirectoryIterator.