homepage Welcome to WebmasterWorld Guest from 54.197.215.146
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Delete Entire Folder Contents With PHP
ukgimp




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

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




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

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

Will that work? :)

Paul in South Africa




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

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

coopster




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

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




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

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);
?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved