PHP 使用 scandir() 查詢目錄中的資料夾
要檢查檔案或資料夾是否正在使用,可以使用 is_dir() 或 is_file() 函式。
scandir 函式是一個內建函式,可返回特定目錄的檔案和目錄陣列。它列出使用者指定的路徑中存在的檔案和目錄。
例如
$scan = scandir('myFolder'); foreach($scan as $file) { if (!is_dir("myFolder/$file")) { echo $file.'
'; } }
輸出
List of files and directories inside the path specified (if any)
資料夾“myFolder”使用“scandir”函式掃描,其中列出其內部的檔案和目錄。“foreach”迴圈針對每個檔案執行,如果“myFolder”資料夾中存在檔案,則將其回顯在螢幕上。
廣告