Given the path of the folder and the task is to print names of subfolders and files present inside them.
Explaination: In our PHP code, initially, it is checked whether provided path or filename is a directory or not using is_dir() function. Now, we open the directory using opendir() function and then checking whether it is getting opened or have some errors. Then we use a while loop to get names of all the subfolders, as well as files, present inside the directory with the help of readdir() function. Now we are going inside each subfolder and reading the names of all the files present inside them following a similar procedure.
Note: This Code have been saved as PHP file and accessed through wampserver
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.