diff --git a/apps/files_archive/lib/storage.php b/apps/files_archive/lib/storage.php
index 86761663611cf5c4462f12f72df28d673a4df462..2f10d6a3e4ee5667d815c9cd7e721a6ebf83943f 100644
--- a/apps/files_archive/lib/storage.php
+++ b/apps/files_archive/lib/storage.php
@@ -49,6 +49,7 @@ class OC_Filestorage_Archive extends OC_Filestorage_Common{
 		OC_FakeDirStream::$dirs[$id]=$content;
 		return opendir('fakedir://'.$id);
 	}
+	public function readdir($path){}
 	public function stat($path){
 		$ctime=filectime($this->path);
 		$path=$this->stripPath($path);
diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php
index 1a6942ad16086ae528d9b5cdaf972975eebe299b..9174334383c6ee2f59aa4ca3e070ed5eea02d0c7 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -139,6 +139,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 		}
 	}
 	
+	public function readdir( $path ) {}
+	
 	public function is_dir($path) {
 		if ($path == "" || $path == "/") {
 			return true;
diff --git a/apps/files_versions/versions.php b/apps/files_versions/versions.php
index 44ce7c635aa3180ff2475f3212b2e062742734ac..6feb0cbb9c7794920b4a44f35abe68483d605a6c 100644
--- a/apps/files_versions/versions.php
+++ b/apps/files_versions/versions.php
@@ -303,66 +303,88 @@ class Storage {
          */
         public static function expireAll() {
 	
-		function deleteAll($directory, $empty = false) {
+		function deleteAll( $directory, $empty = false ) {
 		
-			if(substr($directory,-1) == "/") {
-				$directory = substr($directory,0,-1);
+			// strip leading slash
+			if( substr( $directory, 0, 1 ) == "/" ) {
+			
+				$directory = substr( $directory, 1 );
+				
+			}
+			
+			// strip trailing slash
+			if( substr( $directory, -1) == "/" ) {
+			
+				$directory = substr( $directory, 0, -1 );
+				
 			}
 
-			if(!file_exists($directory) || !is_dir($directory)) {
+			$view = new \OC_FilesystemView('');
+			
+			if ( !$view->file_exists( $directory ) || !$view->is_dir( $directory ) ) {
 			
 				return false;
 				
-			} elseif(!is_readable($directory)) {
+			} elseif( !$view->is_readable( $directory ) ) {
 			
 				return false;
 				
 			} else {
 			
-				$directoryHandle = opendir($directory);
+				$foldername = \OCP\Config::getSystemValue('datadirectory') .'/' . \OCP\USER::getUser() .'/' . $directory; // have to set an absolute path for use with PHP's opendir as OC version doesn't work
+				
+				$directoryHandle = opendir( $foldername );	
 			
-				while ($contents = readdir($directoryHandle)) {
+				while ( $contents = $view->readdir( $directoryHandle ) ) {
 				
-					if( $contents != '.' && $contents != '..') {
+					if ( $contents != '.' && $contents != '..') {
 						
 						$path = $directory . "/" . $contents;
 					
-						if( is_dir($path) ) {
+						if ( $view->is_dir( $path ) ) {
 							
-							deleteAll($path);
+							deleteAll( $path );
 						
 						} else {
-						
-							unlink($path);
+							
+							$view->unlink( \OCP\USER::getUser() .'/' . $path ); // TODO: make unlink use same system path as is_dir
 						
 						}
 					}
 				
 				}
 			
-				closedir( $directoryHandle );
+				//$view->closedir( $directoryHandle ); // TODO: implement closedir in OC_FSV
 
-				if( $empty == false ) {
+				if ( $empty == false ) {
 				
-					if(!rmdir($directory)) {
+					if ( !$view->rmdir( $directory ) ) {
 					
 						return false;
 						
 					}
 					
-				}
+ 				}
 			
 				return true;
 			}
 			
 		}
+		
+		$dir = \OCP\Config::getSystemValue('files_versionsfolder', Storage::DEFAULTFOLDER);
+		
+		deleteAll( $dir, true );
+
+// 		if ( deleteAll( $dir, 1 ) ) {
+// 		
+// 			echo "<h1>deleted ok</h1>";
+// 			
+// 		} else {
+// 			
+// 			echo "<h1>not deleted</h1>";
+// 			
+// 		}
 	
-		/*	
-		// FIXME: make this path dynamic
-		$dir = '/home/samtuke/owncloud/git/oc5/data/admin/versions';
-
-		( deleteAll( $dir, 1 ) ? return true : return false );
-		*/
         }
 
 
diff --git a/lib/filestorage.php b/lib/filestorage.php
index 71ef4aed00be83d86e30b4de67de306cc438edf2..bf353bb0cce43490d67923cee2faa226ccdc3c57 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -28,6 +28,7 @@ abstract class OC_Filestorage{
 	abstract public function mkdir($path);
 	abstract public function rmdir($path);
 	abstract public function opendir($path);
+	abstract public function readdir($path);
 	abstract public function is_dir($path);
 	abstract public function is_file($path);
 	abstract public function stat($path);
diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php
index 44a2ab0f634017d2c80532d8a4d0da24404d63fc..27794fe17c09a24f212a4b7867ffbf98da33d570 100644
--- a/lib/filestorage/local.php
+++ b/lib/filestorage/local.php
@@ -20,6 +20,9 @@ class OC_Filestorage_Local extends OC_Filestorage{
 	public function opendir($path){
 		return opendir($this->datadir.$path);
 	}
+	public function readdir($handle){
+		return readdir($handle);
+	}
 	public function is_dir($path){
 		if(substr($path,-1)=='/'){
 			$path=substr($path,0,-1);
diff --git a/lib/filesystem.php b/lib/filesystem.php
index 89de533d725f78b854b6b5faea9c0297e6dae51d..0d0943d3639a3d7bc77ee380c33df7539bd4f3d8 100644
--- a/lib/filesystem.php
+++ b/lib/filesystem.php
@@ -399,6 +399,9 @@ class OC_Filesystem{
 	static public function opendir($path){
 		return self::$defaultInstance->opendir($path);
 	}
+	static public function readdir($path){
+		return self::$defaultInstance->readdir($path);
+	}
 	static public function is_dir($path){
 		return self::$defaultInstance->is_dir($path);
 	}
diff --git a/lib/filesystemview.php b/lib/filesystemview.php
index 813a87cd74e5eb2815359826744728a6117fa923..da622bcf920589926c4d4730a2bd4b17560b12be 100644
--- a/lib/filesystemview.php
+++ b/lib/filesystemview.php
@@ -158,6 +158,10 @@ class OC_FilesystemView {
 	public function opendir($path){
 		return $this->basicOperation('opendir',$path,array('read'));
 	}
+	public function readdir($handle){
+		$fsLocal= new OC_Filestorage_Local( array( 'datadir' => '/' ) );
+		return $fsLocal->readdir( $handle );
+	}
 	public function is_dir($path){
 		if($path=='/'){
 			return true;