when i use this script ,he prints every directory in bold letters with DIRECTORY written in front
$handle=opendir ('.');
echo "Verzeichnis-Handle: $handle\n";
echo "<br>Dateien:\n <br>";
while (false !== ($file = readdir ($handle))) {
if(!is_dir($file))
echo "$file\n <br>";
else
echo "<b>DIRECTORY $file\n</b><br>";
but if i choose another directory to display, like opendir('.\modules');
a subdirectory which contains folders, he doesn't display them in bold letters but in normal plain text like usually only files are displayed
why this ?
is_dir() function problem
Moderator: General Moderators
-
jakobdoppler
- Forum Commoner
- Posts: 46
- Joined: Wed May 21, 2003 6:16 pm
readdir() does not return the directory name, only the filename.
e.g. you've opened the directory test and there was file/directory subdir in. You had to check test/subdir but your script only checks subdir <=> ./subdir. Prepend the directory name.
e.g. you've opened the directory test and there was file/directory subdir in. You had to check test/subdir but your script only checks subdir <=> ./subdir. Prepend the directory name.
-
jakobdoppler
- Forum Commoner
- Posts: 46
- Joined: Wed May 21, 2003 6:16 pm
requestion
when i use readdir
i get every file/directory name in this directory
so usually all directories & all files in this folder are displayed
when i use opendir(.) he DOES display me all directories in bold letters
and files are not, so when i choose another path
like
.\modules he does not , although there are also files and directories that he returns
but then is_dir doesn't work
i think i think completely wrong ,am i ?
please can u exlain it why i need to prepend the dir , and why this is not necessary with (.)
or even better would be the modified code to do what i want
(just marking directories bols and leaving files blank)
i get every file/directory name in this directory
so usually all directories & all files in this folder are displayed
when i use opendir(.) he DOES display me all directories in bold letters
and files are not, so when i choose another path
like
.\modules he does not , although there are also files and directories that he returns
but then is_dir doesn't work
i think i think completely wrong ,am i ?
please can u exlain it why i need to prepend the dir , and why this is not necessary with (.)
or even better would be the modified code to do what i want
(just marking directories bols and leaving files blank)
let's say you have a directory structure like
But if you open the directory data (same as ./data) readdir will return (e.g.) a.dat. If you put only that name to is_dir it tries to get the info for is_dir('./a.dat'); which doesn't exist.
is_dir('data/a.dat'); would be correct.
- /
- www/
- htdocs/
- script.php
another.file- data/
- a.dat
b.dat
- a.dat
- data/
- script.php
- htdocs/
- www/
But if you open the directory data (same as ./data) readdir will return (e.g.) a.dat. If you put only that name to is_dir it tries to get the info for is_dir('./a.dat'); which doesn't exist.
is_dir('data/a.dat'); would be correct.
Code: Select all
<?php
$path = 'data';
$dd = opendir($path);
$path .= '/';
while( ($filename = readdir($dd)) !== FALSE)
echo $filename, (is_dir($path.filename)) ? ' is a directory' : ' is not a directory';
?>-
jakobdoppler
- Forum Commoner
- Posts: 46
- Joined: Wed May 21, 2003 6:16 pm
thanx
ahh know i got it, thank u very much !!