DirectoryIterator::isDir()函數是PHP中的內置函數,用於檢查當前DirectoryIterator項是否為目錄。
用法:
bool DirectoryIterator::isDir( void )
參數:該函數不接受任何參數。
返回值:如果目錄存在,則此函數返回TRUE,否則返回FALSE。
以下示例程序旨在說明PHP中的DirectoryIterator::isDir()函數:
示例1:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs while directory is valid
while ($directory->valid()) {
// Check for directory element
if ($directory->isDir()) {
$file = $directory->current();
// Display the filename and its size
echo $file->getFilename() . " | Size: "
. $directory->getSize() . "<br>";
}
// Move to the next element
$directory->next();
}
?>
輸出:
. | Size: 4096 .. | Size: 12288 dashboard | Size: 4096 img | Size: 0 webalizer | Size: 0 xampp | Size: 0
示例2:
<?php
// Create a directory Iterator
$directory = new DirectoryIterator(dirname(__FILE__));
// Loop runs while directory is valid
while ($directory->valid()) {
// Check for directory element
if ($directory->isDir()) {
$file = $directory->current();
// Display file name and last modified time
echo $file->getFilename() . " | MTime: "
. $directory->getMTime() . "<br>";
}
// Move to the next element
$directory->next();
}
?>
輸出:
. | MTime: 1574654324 .. | MTime: 1574540515 dashboard | MTime: 1574350724 img | MTime: 1574350724 webalizer | MTime: 1574350718 xampp | MTime: 1574350724
注意:此函數的輸出取決於服務器文件夾的內容。
參考: https://www.php.net/manual/en/directoryiterator.isdir.php
相關用法
- PHP SplFileInfo isDir()用法及代碼示例
- PHP DirectoryIterator key()用法及代碼示例
- PHP DirectoryIterator next()用法及代碼示例
- PHP DirectoryIterator getBasename()用法及代碼示例
- PHP DirectoryIterator seek()用法及代碼示例
- PHP DirectoryIterator getFilename()用法及代碼示例
- PHP DirectoryIterator getExtension()用法及代碼示例
- PHP DirectoryIterator getMTime()用法及代碼示例
- PHP DirectoryIterator getCTime()用法及代碼示例
- PHP DirectoryIterator isLink()用法及代碼示例
- PHP DirectoryIterator getPerms()用法及代碼示例
- PHP DirectoryIterator getType()用法及代碼示例
- PHP DirectoryIterator rewind()用法及代碼示例
- PHP DirectoryIterator isReadable()用法及代碼示例
- PHP DirectoryIterator isWritable()用法及代碼示例
注:本文由純淨天空篩選整理自jit_t大神的英文原創作品 PHP | DirectoryIterator isDir() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。