0

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

4
Contributors
5
Replies
15
Views
7 Years
Discussion Span
Last Post by HavocAngel
0

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 :(

0

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!

0

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

0

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);         
     	}
}

Edited by HavocAngel: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.