diff --git a/lib/files/cache/watcher.php b/lib/files/cache/watcher.php
index d6039d9945c08050c3a883cb6456295b266b7f6d..31059ec7f56883cd9105291c775d4f1f1d77ff13 100644
--- a/lib/files/cache/watcher.php
+++ b/lib/files/cache/watcher.php
@@ -44,12 +44,14 @@ class Watcher {
 	public function checkUpdate($path) {
 		$cachedEntry = $this->cache->get($path);
 		if ($this->storage->hasUpdated($path, $cachedEntry['mtime'])) {
-			if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
+			if ($this->storage->is_dir($path)) {
 				$this->scanner->scan($path, Scanner::SCAN_SHALLOW);
-				$this->cleanFolder($path);
 			} else {
 				$this->scanner->scanFile($path);
 			}
+			if ($cachedEntry['mimetype'] === 'httpd/unix-directory') {
+				$this->cleanFolder($path);
+			}
 			$this->cache->correctFolderSize($path);
 		}
 	}
diff --git a/tests/lib/files/cache/watcher.php b/tests/lib/files/cache/watcher.php
index 0125dd843b97b34510f57f473d7c4c33b3b32328..07c8ac3640cd1c9ee0149ecdbf944d1934f190c2 100644
--- a/tests/lib/files/cache/watcher.php
+++ b/tests/lib/files/cache/watcher.php
@@ -63,6 +63,40 @@ class Watcher extends \PHPUnit_Framework_TestCase {
 		$this->assertFalse($cache->inCache('folder/bar2.txt'));
 	}
 
+	public function testFileToFolder() {
+		$storage = $this->getTestStorage();
+		$cache = $storage->getCache();
+		$updater = new \OC\Files\Cache\Watcher($storage);
+
+		//set the mtime to the past so it can detect an mtime change
+		$cache->put('', array('mtime' => 10));
+
+		$storage->unlink('foo.txt');
+		$storage->rename('folder','foo.txt');
+		$updater->checkUpdate('');
+
+		$entry= $cache->get('foo.txt');
+		$this->assertEquals(-1, $entry['size']);
+		$this->assertEquals('httpd/unix-directory', $entry['mimetype']);
+		$this->assertFalse($cache->inCache('folder'));
+		$this->assertFalse($cache->inCache('folder/bar.txt'));
+
+		$storage = $this->getTestStorage();
+		$cache = $storage->getCache();
+		$updater = new \OC\Files\Cache\Watcher($storage);
+
+		//set the mtime to the past so it can detect an mtime change
+		$cache->put('foo.txt', array('mtime' => 10));
+
+		$storage->unlink('foo.txt');
+		$storage->rename('folder','foo.txt');
+		$updater->checkUpdate('foo.txt');
+
+		$entry= $cache->get('foo.txt');
+		$this->assertEquals('httpd/unix-directory', $entry['mimetype']);
+		$this->assertTrue($cache->inCache('foo.txt/bar.txt'));
+	}
+
 	/**
 	 * @param bool $scan
 	 * @return \OC\Files\Storage\Storage