Skip to content

Loading…

Added directory deletion #254

Closed
wants to merge 1 commit into from

2 participants

@tourshi

Delete function is now fully functional, deletes files, folder, and folders with files (recursively).

Thanks alot _h5ai team, you guys have great code :)

@tourshi tourshi Added Directory deletion
Delete function is now fully functional, deletes files, folder, and folders with files (recursively). 

Thanks alot _h5ai team, you guys have great code :)
9b736c1
@lrsjng lrsjng added the Patch label
@LeafyDev LeafyDev referenced this pull request
Closed

Deleting directory fails. #284

@lrsjng
Owner

Added with 62e60cf

@lrsjng lrsjng closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 28, 2014
  1. @tourshi

    Added Directory deletion

    tourshi committed
    Delete function is now fully functional, deletes files, folder, and folders with files (recursively). 
    
    Thanks alot _h5ai team, you guys have great code :)
Showing with 14 additions and 2 deletions.
  1. +14 −2 src/_h5ai/server/php/inc/Api.php
View
16 src/_h5ai/server/php/inc/Api.php
@@ -171,7 +171,19 @@ public function apply() {
$abs_path = $this->app->get_abs_path($href);
if (!unlink($abs_path)) {
- $errors[] = $href;
+ //check if it's a directory
+ if(is_dir($abs_path)) {
+ //check for files & folders within dir, deletes them, recursively (from SOF, barbushin | tested in PHP 5.4)
+ foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($abs_path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
+ $path->isFile() ? unlink($path->getPathname()) : rmdir($path->getPathname());
+ }
+ rmdir($abs_path);
+
+ } else {
+ //return error if neither dir or file could be deleted
+ $errors[] = $href;
+ }
+
}
}
}
@@ -212,4 +224,4 @@ public function apply() {
}
}
-?>
+?>
Something went wrong with that request. Please try again.