Delete or Remove all files and folders in a directory‎

If you want to delete everything from folder (including subfolders) use this function.

function removeDir( $dir )
{
   if ( is_dir( $dir ) ) {
      $objects = scandir( $dir );
      foreach ( $objects as $object ) {
         if ( $object != "." && $object != ".." ) {
            if ( filetype( $dir . "/" . $object ) == "dir" ) {
               rrmdir( $dir . "/" . $object );
            }
            else {
               unlink( $dir . "/" . $object );
            }
         }
      }
 
      reset( $objects );
      rmdir( $dir );
   }
 
   return true;
}
 
removeDir( '/foo/' );

Tags

No tag here.

Recommended pages

Resize image function...

Resize image function for jpg format. $mood between max and min. if you choose max, this mean max size of image is $ta otherwise min size of image is $ta. function makeTheThumb( $ppath, $ta, $mood ) ...

Human readable file size...

This function return formatting of file sizes in a human readable format. function formatFileSize( $size ) { $file_size = $size; $i = 0;   $name = array( 'byte', 'kB', 'MB', '...

Get all subsets of array...

If you have a list of items (for example)......

Extract numbers from a unicode string...

Quick extract numbers from a unicode string......