mpsn Posted November 3, 2011 Share Posted November 3, 2011 Hi, how do I output the total files in a given directory? Here is code I cannot get to work: <?php $file=fopen('C:\\dir\\folder\\proj_ath\\', 'a+'); for($i=0;$i<count($file);$i++) { print "tot files so far: $i <br />"; } ?> Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250353-how-to-output-total-files-in-a-directory/ Share on other sites More sharing options...
trq Posted November 3, 2011 Share Posted November 3, 2011 fopen is used to open a file. echo count(glob('C:\\dir\\folder\\proj_ath\\*')); I'm not how well that will work on windows and it will also count directories as files. Quote Link to comment https://forums.phpfreaks.com/topic/250353-how-to-output-total-files-in-a-directory/#findComment-1284532 Share on other sites More sharing options...
mpsn Posted November 3, 2011 Author Share Posted November 3, 2011 Yes, I also found out about glob just now. Apparently it's good for directories with < 100 files, this is what I used: <?php $dir = "C:/xampp/htdocs/proj_ath/"; $xmlFiles = glob($dir . "*.xml"); //print each file name foreach($xmlFiles as $xmlFile) { print $xmlFile."<br />"; } ?> Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/250353-how-to-output-total-files-in-a-directory/#findComment-1284535 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.