We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

what are the dots when U use PHP readdir function?

nooch44
nooch44 asked
on
Medium Priority
323 Views
Last Modified: 2012-05-06
hey,
when i use the readdir function to list the contents of a directory the first two listings are always '.' and '..' - can anyone explain what they are and if there is a way to exclude them from echoing ive attached the code
//code
$dir_1 = opendir("landscapes");
   while ($read_file = readdir($dir_1)) {
      echo "$read_file"."<br>";
   }
closedir($dir_1);
 
//output
.
..
600height4.jpg
600height5.jpg
600height7.jpg
adr11.jpg
adr20.jpg
adr21.jpg
adr22.jpg
baker-post-office.jpg
image.jpg
imagemountain.jpg.

Open in new window

Comment
Watch Question

Commented:
. is your current directory
.. is the previous directory

They are generally found on unix systems, as it's a way of navigating between directories.

Do this:

$excludeddirs = array('.', '..');

   while ($read_file = readdir($dir_1)) {
      if (!in_array($read_file, $excludeddirs)) {
        echo "$read_file"."<br>";
      }
   }

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
perfect...thanks for the help
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.