note 26244 deleted from function.rmdir by tomsommer

From: Date: Sat, 07 Aug 2004 23:47:21 +0000
Subject: note 26244 deleted from function.rmdir by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-74168@lists.php.net to get a copy of this message
Note Submitter: Yet another recursive dir remover... ---- 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; }

« previous php.notes (#74168) next »