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. Link to comment https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/ Share on other sites More sharing options...
trq Posted July 5, 2007 Share Posted July 5, 2007 scandir. Link to comment https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/#findComment-290778 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? Link to comment https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/#findComment-290798 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; } } ?> Link to comment https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/#findComment-290808 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... Link to comment https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/#findComment-290815 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. Link to comment https://forums.phpfreaks.com/topic/58620-solved-folder-contents-function/#findComment-290839 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.