Jump to content

[SOLVED] Folder Contents Function?


sKunKbad

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.