Revision 7eb2e498
Added by Colin Smith over 20 years ago
etc/inc/pfsense-utils.inc | ||
---|---|---|
910 | 910 |
} |
911 | 911 |
|
912 | 912 |
/* |
913 |
* rmdir_recursive($path,$followLinks=false)
|
|
913 |
* rmdir_recursive($path,$follow_links=false)
|
|
914 | 914 |
* Recursively remove a directory tree (rm -rf path) |
915 | 915 |
* This is for directories _only_ |
916 | 916 |
*/ |
917 | 917 |
function rmdir_recursive($path,$follow_links=false) { |
918 |
$dir = opendir($path) ; |
|
919 |
|
|
920 |
while ($entry = readdir($dir)) { |
|
921 |
if (is_file("$path/$entry") || ((!$follow_links) && is_link("$path/$entry"))) |
|
922 |
unlink("$path/$entry"); |
|
923 |
elseif (is_dir("$path/$entry") && $entry!='.' && $entry!='..') |
|
924 |
rmdir_recursive("$path/$entry"); |
|
918 |
$to_do = glob($path); |
|
919 |
if(!is_array($to_do)) { |
|
920 |
$dir = opendir($path); |
|
921 |
while ($entry = readdir($dir)) { |
|
922 |
if (is_file("$path/$entry") || ((!$follow_links) && is_link("$path/$entry"))) |
|
923 |
unlink("$path/$entry"); |
|
924 |
elseif (is_dir("$path/$entry") && $entry!='.' && $entry!='..') |
|
925 |
rmdir_recursive("$path/$entry"); |
|
926 |
} |
|
927 |
closedir($dir); |
|
928 |
} else { |
|
929 |
foreach($to_do as $workingdir) { // Handle wildcards by foreaching. |
|
930 |
$dir = opendir($workingdir); |
|
931 |
while ($entry = readdir($dir)) { |
|
932 |
if (is_file("$workingdir/$entry") || ((!$follow_links) && is_link("$workingdir/$entry"))) |
|
933 |
unlink("$workingdir/$entry"); |
|
934 |
elseif (is_dir("$workingdir/$entry") && $entry!='.' && $entry!='..') |
|
935 |
rmdir_recursive("$workingdir/$entry"); |
|
936 |
} |
|
937 |
closedir($dir); |
|
938 |
} |
|
925 | 939 |
} |
926 |
closedir($dir) ; |
|
927 | 940 |
return rmdir($path); |
928 | 941 |
} |
929 | 942 |
|
Also available in: Unified diff
Add wildcard support to rmdir_recursive().