Welcome to WebmasterWorld Guest from 54.167.29.212

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Delete Entire Folder Contents With PHP

     

ukgimp

12:25 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What is the best way of deleting an entire folders contents in php

I looked at this, but not sure exactly how to implement.

[uk.php.net...]

I dont want to get involved with something that could mash my system if I get it wrong.

Cheers

ukgimp

12:33 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



unlink("/path/to/folder/","*.php");

Will that work? :)

Paul in South Africa

1:28 pm on Mar 18, 2004 (gmt 0)

10+ Year Member



The function you need is rmdir() [uk.php.net]

coopster

6:41 pm on Mar 18, 2004 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



rmdir will not remove the directory if the directory is not empty and you will receive a warning message. You would either have to loop through and unlink any existing files, or you could invoke a system command on the directory.

jatar_k

6:42 pm on Mar 19, 2004 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member



you could loop it like this too

<? 
$mydir = "/path/to/dir/";
$d = dir($mydir);
while($entry = $d->read()) {
if ($entry!= "." && $entry!= "..") {
unlink($entry);
}
}
$d->close();
rmdir($mydir);
?>
 

Featured Threads

Hot Threads This Week

Hot Threads This Month