sKunKbad Posted July 5, 2007 Share Posted July 5, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted July 5, 2007 Share Posted July 5, 2007 scandir. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 5, 2007 Author Share Posted July 5, 2007 scandir. Thanks Thorpe, Why is it that with dir or scandir they always have the "." and the ".." listed as files? Quote Link to comment Share on other sites More sharing options...
trq Posted July 5, 2007 Share Posted July 5, 2007 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; } } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted July 5, 2007 Share Posted July 5, 2007 Oh! Just to think I wrote a nice script to read the contents of a folder as well and sort the files and folders separately in alphabetical order. If I'd have known about scandir() it'd have made my script a whole lot shorter... Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 5, 2007 Author Share Posted July 5, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.