- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP using scandir() to find folders in a directory
To check if a folder or a file is in use, the function is_dir() or is_file() can be used.
The scandir function is an inbuilt function that returns an array of files and directories of a specific directory. It lists the files and directories present inside the path specified by the user.
For example
$scan = scandir('myFolder'); foreach($scan as $file) { if (!is_dir("myFolder/$file")) { echo $file.'
'; } }
Output
List of files and directories inside the path specified (if any)
The directory ‘myFolder’ is scanned using the ‘scandir’ function and the files and directories inside it are listed out. The ‘foreach’ loop is run over every file and if there is a file in the directory ‘myFolder’, it is echoed on the screen.
Advertisements