Forum Moderators: coopster

Message Too Old, No Replies

Removing all files and folders in a directory

         

Habtom

9:31 am on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is there a built in function to clear up everything in the root directory of a domain, or should I loop through the folders and remove directories and unlink the files? Any other suggestions.

[edited by: Habtom at 9:32 am (utc) on Aug. 23, 2006]

siMKin

1:28 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



this should do the trick:

function rm_all($dir) 
{
if (@$fp = opendir($dir))
{
while (($file = readdir($fp))!== false)
{
if (($file!= '.') && ($file!= '..'))
{
if (is_dir($dir."/".$file))
{
rm_all($dir."/".$file);
rmdir($dir."/".$file);
}
else
{
unlink($dir."/".$file);
}
}
}
}
else
{
echo "coulnd't open ".$dir."<br>\n";
}
}

//edit
hmmm...for some reason, the forum keeps removing my tabs.

[edited by: siMKin at 1:30 pm (utc) on Aug. 23, 2006]

Habtom

12:42 pm on Aug 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, that helped.

eelixduppy

1:33 pm on Aug 29, 2006 (gmt 0)



>>>hmmm...for some reason, the forum keeps removing my tabs.

Take a look at this thread [webmasterworld.com] on indentation.