- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get all subdirectories of a given directory in PHP
To get the subdirectories present in a directory, the below lines of code can be used −
<?php $all_sub_dirs = array_filter(glob('*.*'), 'is_dir'); print_r($all_sub_dirs); ?>
This will produce the following output. The glob function is used to get all the subdirectories of a specific directory−
Array (  => demo.csv  => mark.php  => contact.txt  => source.txt )
To get only the directories, the below lines of code can be used−
<?php $all_dirs = glob($somePath . '/*' , GLOB_ONLYDIR); print_r($all_dirs); ?>
This will produce the following output. The glob function is used by specifying that only directories need to be extracted−
Array (  => example  => exam  => log )
- How to Count Number of Files and Subdirectories inside a Given Linux Directory?
- How to grep a string in a directory and all its subdirectories in Linux?
- Get Root Directory Path of a PHP project?
- PHP: Unlink All Files Within A Directory, and then Deleting That Directory
- How to use the sed command to replace a text in files present in a directory and subdirectories?
- How to get a list of all sub-directories in the current directory using Python?
- How to Zip a directory in PHP?
- Get all the images from a folder in PHP
- Python program to get all subsets of a given size of a set
- Python program to get all subsets of given size of a set
- Java Program to get the content of a directory
- Get Java Home Directory
- How to check if a given directory contains any other directory in Python?
- How do I list all files of a directory in Python?
- PHP – How to get the Unicode point value of a given character?