For looping all files in a directory, I created this code in php :
$dir = new DirectoryIterator(dirname(__FILE__));
$files = scandir($dir.'/');
foreach($files as $file)
{
echo $file;
echo "\n";
}
However I am not able to list all files inside multiple subdirectory of a directory.
Use RecursiveDirectoryIterator
<?php
$path = realpath('/etc');
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objects as $name => $object){
echo "$name\n";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With