I’m working on a project locally to copy some information from some files into new files to make the content easier to study. I’ve successfully used the functions opendir and readdir to get a list of files I need from the directory but I’m not sure how to use the variable with the array to implement the file_get_comments function. Here is the function I"m using to obtain my list into an array.
error_reporting(E_ALL);
function getDirectory( $path = '.', $level = 0 ){
$ignore = array( 'cgi-bin', '.', '..' );
// Directories to ignore when listing output. Many hosts
// will deny PHP access to the cgi-bin.
$dh = opendir( $path );
// Open the directory to the handle $dh
while( false !== ( $file = readdir( $dh ) ) ){
// Loop through the directory
if( !in_array( $file, $ignore ) ){
// Check that this file is not to be ignored
$spaces = str_repeat( ' ', ( $level * 4 ) );
// Just to add spacing to the list, to better
// show the directory tree.
if( is_dir( "$path/$file" ) ){
// Its a directory, so we need to keep reading down...
echo "<strong>$spaces $file</strong><br />";
getDirectory( "$path/$file", ($level+1) );
// Re-call this same function but on a new directory.
// this is what makes function recursive.
} else {
echo "$spaces $file<br />";
// Just print out the filename
}
}
}
closedir( $dh );
// Close the directory handle
}
getDirectory("f:/wamp/www/courses/coursmat/contents/video-lectures/");
This returns a list of all the files in all of the sub-directories of the video-lectures directory.
I think a foreach statement would be used but I’m not sure how to approach it. I’d like to target only the index.html files and put them in an array for use in the file_get_contents.
Thanks in advance.