循环通过dirs来查看哪些是可写的

时间:2013-08-14 23:22:30

标签: php loops

<?php
$iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator('./'), 
            RecursiveIteratorIterator::SELF_FIRST);

foreach($iterator as $file) {
    if($file->isDir()) {
        echo "\n" . strtoupper($file->getRealpath()), PHP_EOL;
    }
}
?>

以上就是我到目前为止所做的。我希望通过dirs和sub-dirs看看哪些是可写的。

1 个答案:

答案 0 :(得分:0)

您是否尝试过使用isWritable()方法?

<?php
$iterator = new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator('./'), 
            RecursiveIteratorIterator::SELF_FIRST);

foreach($iterator as $file) {
    if($file->isDir()) {
        echo "\n" . strtoupper($file->getRealpath()), PHP_EOL;
        if($file->isWritable()) {
            echo "directory is writable\n";
        }
    }

}
?>

http://www.php.net/manual/en/splfileinfo.iswritable.php