List only the files from folders
Posted: Sat Dec 12, 2009 3:23 pm
Hello,
The structure is for example:
Sellers
---test1
--------new folder
--------orders
--------file1.txt
--------file2.txt
--------file3.txt
---test2
--------file1.txt
---index.php
---list.php
list.php is
and the result:
Why are 'new folder' and 'orders' not considered folders ?
I used var_dump to print the check, if I'd used the condition I would have got everything.
Thank you
The structure is for example:
Sellers
---test1
--------new folder
--------orders
--------file1.txt
--------file2.txt
--------file3.txt
---test2
--------file1.txt
---index.php
---list.php
list.php is
Code: Select all
<?php
$dir = ".";
$bad = array(".", "..");
$contents = scandir($dir);
$folders = array_diff($contents, $bad);
foreach (array_values($folders) as $foldername) {
if (is_dir($foldername)) {
echo "Folder: $foldername<br />\n";
$subfolder = scandir("$foldername");
$files = array_diff($subfolder, $bad);
foreach (array_values($files) as $filename) {
var_dump(is_dir($filename));
echo "Filename: $filename<br />\n";
}
echo '<br>';
}
}
//print_r($files);
?>Code: Select all
Folder: test1
bool(false) Filename: new folder
bool(false) Filename: list_1260506826.txt
bool(false) Filename: list_1260511368.txt
bool(false) Filename: list_1260553280.txt
bool(false) Filename: orders
Folder: test2
bool(false) Filename: DB20091203211632.txtI used var_dump to print the check, if I'd used the condition
Code: Select all
if(!is_dir...Thank you