the_oliver Posted October 21, 2007 Share Posted October 21, 2007 Hello, Im trying to find a list of all the files on a folder, and place them into an array. I have been attempting, to little avail, to do this with system(). When run, it will print to screen all of the files, but when i try to break it into and array using the following code i only get the last file in the list. Can anyone help me solve this please? <?php $arr = explode(" ", system('ls')); echo "<br><br><br>".$arr['0']."<br>".$arr['1']."<br>".$arr['2']; ?> - Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/74229-solved-systemls-into-array/ Share on other sites More sharing options...
cooldude832 Posted October 21, 2007 Share Posted October 21, 2007 Check your delimieter, it might not be a " ", I do not know what the otuput of ls looks like as I'm on a vista machiene Quote Link to comment https://forums.phpfreaks.com/topic/74229-solved-systemls-into-array/#findComment-374965 Share on other sites More sharing options...
the_oliver Posted October 21, 2007 Author Share Posted October 21, 2007 Ah yes, should have thought to post that. It looks like: file1.php file2.php file3.php etc... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/74229-solved-systemls-into-array/#findComment-374966 Share on other sites More sharing options...
Orio Posted October 21, 2007 Share Posted October 21, 2007 Check out glob(). It returns an array with all the files that match the pattern, but you can use it to return all of the files. Also, you can check out scandir() which also does the same thing. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/74229-solved-systemls-into-array/#findComment-374967 Share on other sites More sharing options...
the_oliver Posted October 21, 2007 Author Share Posted October 21, 2007 glob() worked a treat! Many Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/74229-solved-systemls-into-array/#findComment-374972 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.