note 26244 added to function.rmdir

From: Date: Wed, 23 Oct 2002 20:51:44 +0000
Subject: note 26244 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-38467@lists.php.net to get a copy of this message
function delete_dir ($del_path) { //be careful with this.. you could remove your entire site if its pointed to root :) //set path to current dir $this_path = getcwd(); if (is_dir($del_path)) { //open dir, read files chdir($del_path); $handle=opendir('.'); while (($file = readdir($handle))!==false) { if (($file != ".") && ($file != "..")) { if (is_dir($file)) { //do recursive stuff if the "file" is a dir delete_dir($file."/"); } if (is_file($file)) { //delete all files in the dir chdir($this_path); unlink($del_path.$file); chdir($del_path); } } } closedir($handle); //close dir } //go to where we know chdir($this_path); //replace the web path with the dir path and remove the now empty dir rmdir( ereg_replace("/","\\",$del_path) ); return; } -- http://www.php.net/manual/en/function.rmdir.php http://master.php.net/manage/user-notes.php?action=edit+26244 http://master.php.net/manage/user-notes.php?action=delete+26244 http://master.php.net/manage/user-notes.php?action=reject+26244

« previous php.notes (#38467) next »