diff --git a/lib/filelib.php b/lib/filelib.php
index <HASH>..<HASH> 100644
--- a/lib/filelib.php
+++ b/lib/filelib.php
@@ -677,7 +677,7 @@ function file_save_draft_area_files($draftitemid, $contextid, $component, $filea
             }
             // unchanged file or directory - we keep it as is
             unset($newhashes[$oldhash]);
-            if (!$file->is_directory()) {
+            if (!$oldfile->is_directory()) {
                 $filecount++;
             }
         }
MDL-<I> File API: Fixed calculation of the number of current files when merging with the draft area