note 95679 added to function.rmdir

From: Date: Fri, 15 Jan 2010 13:04:43 +0000
Subject: note 95679 added to function.rmdir
Groups: php.notes 
Request: Send a blank email to php-notes+get-165002@lists.php.net to get a copy of this message
delTree in comments below doesn't work in windows. Here is the fix - using DIRECTORY_SEPARATOR instead of '/' function delTree($dir) { $files = glob( $dir . '*', GLOB_MARK ); foreach( $files as $file ){ if( substr( $file, -1 ) == DIRECTORY_SEPARATOR ) delTree( $file ); else unlink( $file ); } if (is_dir($dir)) rmdir( $dir ); } This function however doesn't delete ".svn" directories. I don't know is it possible with glob, but i rewrote delTree using RecursiveDirectoryIterator (PHP 5 >= 5.1.2), which does the job. delTree($dir) { $dirIterator = new RecursiveDirectoryIterator($dir); $iterator = new RecursiveIteratorIterator($dirIterator, RecursiveIteratorIterator::CHILD_FIRST); foreach ($iterator as $file) { if ($file->isDir()) { delTree((string) $file); } elseif ($file->isFile()) { unlink($file); } } if (is_dir($dir)) rmdir($dir); } ---- Server IP: 69.147.83.197 Probable Submitter: 93.152.182.168 ---- Manual Page -- http://www.php.net/manual/en/function.rmdir.php Edit -- https://master.php.net/note/edit/95679 Del: integrated -- https://master.php.net/note/delete/95679/integrated Del: useless -- https://master.php.net/note/delete/95679/useless Del: bad code -- https://master.php.net/note/delete/95679/bad+code Del: spam -- https://master.php.net/note/delete/95679/spam Del: non-english -- https://master.php.net/note/delete/95679/non-english Del: in docs -- https://master.php.net/note/delete/95679/in+docs Del: other reasons-- https://master.php.net/note/delete/95679 Reject -- https://master.php.net/note/reject/95679 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#165002) next »