I have a test directory that contains one directory and one file. I want my program to search through this test directory and find the file. But the code is not recognizing the sub-directory as a directory and treats it as a file. The section of code where I am testing for this looks like this. I am testing in three different ways trying to find the problem.
Code:
$dir_handle = @opendir($srce) or die("Unable to open $srce");
while (false !== ($file = readdir($dir_handle))) {
var_dump(is_dir('$file')) . "\n";
if (is_dir($file))
echo 'Dir1 = '.$file.'<br>';
if (filetype($file) == "dir")
echo 'Dir2 = '.$file.'<br>';
When the test directory is read, I get four entries:
. //should be a dir
.. //should be a dir
edited //should be a dir
file.php //should be a file
The output of var_dump is false for all four while is_dir and filetype recognize the first two as directories but the see the last two as files. Can anyone see where I might be going wrong?
Jack