diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index f2438a5487b36faf23776d175a454818c37936da..387667a81a9eabea436917606ad770f9166d685f 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -40,8 +40,11 @@ abstract class StreamWrapper extends Common {
 	}
 
 	public function rmdir($path) {
-		if ($this->file_exists($path) && $this->isDeletable($path)) {
+		if ($this->is_dir($path) && $this->isDeletable($path)) {
 			$dh = $this->opendir($path);
+			if (!is_resource($dh)) {
+				return false;
+			}
 			while (($file = readdir($dh)) !== false) {
 				if ($this->is_dir($path . '/' . $file)) {
 					$this->rmdir($path . '/' . $file);