Hi ![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
As you can see, I'm trying to add a directory renaming feature to the function below thanks to the insertion of this line :
rename($path . "/", str_replace("/temp/", "/new/", $path . "/"));
The problem is that, very logically, once a directory is renamed, the renaming prevents the function from continuing its scan based on an old directory name. Well, that's the way I understand it![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
What I would like to know is how to force the function to start over once a directory has been renamed.
Thanks a lot for the help![Smile :) :)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
As you can see, I'm trying to add a directory renaming feature to the function below thanks to the insertion of this line :
rename($path . "/", str_replace("/temp/", "/new/", $path . "/"));
The problem is that, very logically, once a directory is renamed, the renaming prevents the function from continuing its scan based on an old directory name. Well, that's the way I understand it
What I would like to know is how to force the function to start over once a directory has been renamed.
Thanks a lot for the help
Code:
function hd_dir_scan($directory, $name_before = FALSE, $name_after = FALSE, $filter = FALSE) {
// if the path has a slash at the end we remove it here
if(substr($directory,-1) == "/") $directory = substr($directory,0,-1);
// if the path is not valid or is not a directory ...
if(!file_exists($directory) || !is_dir($directory)) {
// ... we return false and exit the function
return FALSE;
// ... else if the path is readable
} else if(is_readable($directory)) {
// we open the directory
$directory_list = opendir($directory);
// and scan through the items inside
while (FALSE !== ($file = readdir($directory_list))) {
// if the filepointer is not the current directory
// or the parent directory
if($file != "." && $file != "..") {
// we build the new path to scan
$path = $directory . "/" . $file;
// if the path is readable
if(is_readable($path)) {
// we split the new path by directories
$subdirectories = explode("/",$path);
// if the new path is a directory
if(is_dir($path)) {
rename($path . "/", str_replace("/temp/", "/new/", $path . "/"));
// add the directory details to the file list
$directory_tree[] = array(
'path' => $path,
'name' => end($subdirectories),
'kind' => 'directory',
// we scan the new path by calling this function
'content' => hd_dir_scan($path, $filter));
// if the new path is a file
} else if(is_file($path)) {
// get the file extension by taking everything after the last dot
$extension = end(explode(".",end($subdirectories)));
// if there is no filter set or the filter is set and matches
if($filter === FALSE || $filter == $extension) {
// add the file details to the file list
$directory_tree[] = array(
'path' => $path,
'name' => end($subdirectories),
'extension' => $extension,
'size' => filesize($path),
'kind' => 'file');
}
}
}
}
}
// close the directory
closedir($directory_list);
// return file list
return $directory_tree;
// if the path is not readable ...
} else {
return FALSE;
}
}