

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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.'\n'; } }
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.
- Related Questions & Answers
- PHP: fopen to create folders
- How to Zip a directory in PHP?
- PHP: Unlink All Files Within A Directory, and then Deleting That Directory
- Get all subdirectories of a given directory in PHP
- Get Root Directory Path of a PHP project?
- How to create a directory using Python?
- How to remove a directory using Python?
- How to create a directory using Java?
- How to create a Directory using C#?
- How to find if a directory exists in Python?
- How to display files/folders including hidden files/folders in PowerShell?
- How to find the real user home directory using Python?
- How to remove hidden files and folders using Python?
- How to delete folder and sub folders using Java?
- How to Zip / Unzip files or folders using PowerShell?
Advertisements