Jump to content

How to output total files in a directory


mpsn

Recommended Posts

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!

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.

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.