How can I delelte a tree directory structure with php4? I can have any number of directories with any number of files inside. Thanks a lot for the answers
You would use the unlink() command: http://www.php.net/manual/en/function.unlink.php You would need to build a loop structure to enter each directory and delete the files within it. I believe there is a sample function there in the annotations that will do it. I did not check it for accuracy.
function empty_directory($dir_name){ $directory_content = glob ("$dir_name/*", GLOB_BRACE); foreach($directory_content as $item_name){ if(is_file($item_name)){ unlink($item_name);} if(is_dir($item_name)){ empty_directory($item_name);} } return; } //Empty deleteme directory empty_directory('deleteme'); PHP: This should do. Peace,
If you want to delete a tree, and a tree - is an array, then you would need to unset every item of an array in cycle, like: foreach ( $array as $i => $item ) unset ($array[$i]); PHP: