I just want to scan through a directory containing several subdirectories, each containing several text files, and display the name/word count/character count of each text file in each subdirectory.

All I'm looking for is a quick and simple way to do the scanning through all subdirectories finding each file.

thanks in advance

Hi
I think your looking for something like this:

<?php
$dir    = '/directory to be scanned';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);

print_r($files1);
print_r($files2);
?>

Obviouslt you'l want to clean up the array and echo it in a better fashon but print_r does the job to show you whats happening.

Hope this helps


Have I helped? Add to my reputation, I need it :(

I'm afraid that's not what I'm looking for, it only lists the names of any files and subdirectories in the directory specified.

I'm trying to list the names of all files within all subdirectories of the specified directory.

thanks for the reply though!

Here's a bit of code that might help:

<?php

function recurseDir($dir){
     		if(is_dir($dir)){
 				if($dh = opendir($dir){
	 				while(($file = readdir($dh)) !== false){
		 				if($file != '.' && $file != '..'){
			 			     if(!is_dir($dir . $file)){
				 			  	echo $dir . $file;   
			 			     }else{
                                                            echo $dir . $file;
                                                            // since it is a directory we recurse it.
				 			    recurseDir($dir . $file); 
			 			     }	
		 				}
	 				}
 				}
 				closedir($dh);         
     		}
	}

?>

This should go through each directory and display all files

Fixed. And resurrecting a year old thread :D

function recurseDir($dir) {
	if(is_dir($dir)) {
		if($dh = opendir($dir)){
			while($file = readdir($dh)){
				if($file != '.' && $file != '..'){
					if(is_dir($dir . $file)){
						echo $dir . $file;
						// since it is a directory we recurse it.
						recurseDir($dir . $file . '/');
					}else{
						echo $dir . $file;   
			 		}
				}
	 		}
		}
 		closedir($dh);         
     	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.