Exemple #1
0
 /**
  * Deletes a folder by uri.
  */
 public static function deleteFolderUri($uri, $ignore_usage = FALSE)
 {
     // Get folder content without any filtering.
     $content = Imce::scanDir($uri);
     if (!empty($content['error'])) {
         return FALSE;
     }
     // Delete subfolders first.
     foreach ($content['subfolders'] as $path) {
         if (!static::deleteFolderUri($path, $ignore_usage)) {
             return FALSE;
         }
     }
     // Delete files.
     foreach ($content['files'] as $path) {
         if (!static::deleteFileUri($path, $ignore_usage)) {
             return FALSE;
         }
     }
     // Recently emptied folders need some refreshing before the removal on windows.
     if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
         @closedir(@opendir($uri));
     }
     // Remove the folder
     return rmdir($uri);
 }
Exemple #2
0
 /**
  * Deletes a folder by uri.
  */
 public static function deleteFolderUri($uri, $ignore_usage = FALSE, $check_files = FALSE)
 {
     // Get folder content without any filtering.
     $content = Imce::scanDir($uri);
     if (!empty($content['error'])) {
         return FALSE;
     }
     if ($check_files && !empty($content['files'])) {
         drupal_set_message(t('%folder contains files and can not be deleted.', array('%folder' => \Drupal::service('file_system')->basename($uri))), 'error');
         return FALSE;
     }
     // Delete subfolders first.
     foreach ($content['subfolders'] as $path) {
         if (!static::deleteFolderUri($path, $ignore_usage, $check_files)) {
             return FALSE;
         }
     }
     // Delete files.
     foreach ($content['files'] as $path) {
         if (!static::deleteFileUri($path, $ignore_usage)) {
             return FALSE;
         }
     }
     // Recently emptied folders need some refreshing before the removal on windows.
     if (strncasecmp(PHP_OS, 'WIN', 3) == 0) {
         @closedir(@opendir($uri));
     }
     // Remove the folder
     return rmdir($uri);
 }