Jump to content

Recommended Posts

I'm looking for a function that puts the contents of a folder (the file names) into an array. Is there such a beast? For instance, if there is a folder off of my root called /tips/, and I want to list the files that are in it, such as tip1.txt, tip2.txt, etc.

Link to comment
https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/
Share on other sites

Why is it that with dir or scandir they always have the "." and the ".." listed as files?

 

Because they are. Everything is a file in linux . and .. are no exception.

 

. is a link pointing to the current directory, while

.. is a link pointing to the current directories parent.

 

You can simply avoid them within output by using an if(). eg;

 

<?php

  $d = scandir('foo');
  foreach($d as $f) {
    if ($f != '.' || $f != '..') {
      echo $f;
    }
  }

?>

Why is it that with dir or scandir they always have the "." and the ".." listed as files?

 

Because they are. Everything is a file in linux . and .. are no exception.

 

. is a link pointing to the current directory, while

.. is a link pointing to the current directories parent.

 

You can simply avoid them within output by using an if(). eg;

 

<?php

  $d = scandir('foo');
  foreach($d as $f) {
    if ($f != '.' || $f != '..') {
      echo $f;
    }
  }

?>

 

In order for that to work, I had to replace the || with &&. Thanks for your help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.