Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

directory script problem 1

Status
Not open for further replies.

IDTstudios1

Programmer
Aug 8, 2004
72
US
The following script keeps puting dots before the actual directory. Basically it outputs:

<a>.</a><br><a>..</a><br><a>testone</a><br><a>testtwo</a>

when it should output:

<a>testone</a><br><a>testtwo</a>

Script:

$dir = "albums/";

if (is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false) //while files and folders are being read
{
if (filetype($dir . $file) == dir) //if the filetype is a directory and not a file
{

echo '<a>' . $file .'</a><br>';
}
}
closedir($dh);
}
}


Any help would be great,
Thanks
 
um, that's because the first two files in EVERY directory are the "." file (which means "the current directory") and the ".." file (which means "the directory above this one"

Its why you can do things like "cd .." literally "change directory to the directory above this one" and "move file_to_move.txt ." which means move this file to the current directory. Its a remnant of the FAT file system.

go to a command prompt and type "dir" and you'll see the same thing.

The only way to get rid of them would be to basically say

Code:
        if (filetype($dir . $file) == dir) //if the filetype is a directory and not a file
         {
             if ($file != ".") && ($file != "..") )
             {  
                  echo '<a>' . $file .'</a><br>';
             }
         }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top