Index: app/Http/Controllers/Dashboard/DepartmentsController.php
===================================================================
--- app/Http/Controllers/Dashboard/DepartmentsController.php	(revision 1c17e70fdb646adb10dabb9aee5dbe8a5427853f)
+++ app/Http/Controllers/Dashboard/DepartmentsController.php	(revision 159e7df5cac7501076108bf1a80ef55c96981454)
@@ -124,33 +124,26 @@
         $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
         $path = Storage::disk('uploads')->path('Departments');
-        $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
-        $flag=false;
 
-        foreach ($files as $file)
-        {
-            if(File::all()->count() > 0) {
+        try {
+            $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
+            $flag = false;
 
-                // We're skipping all subfolders
-                if (!$file->isDir()) {
-                    $filePath = $file->getRealPath();
-                    // extracting filename with substr/strlen
-                    $relativePath = substr($filePath, strlen($path) + 1);
-                    $zip->addFile($filePath, $relativePath);
+            foreach ($files as $file) {
+
+                    // We're skipping all subfolders
+                    if (!$file->isDir()) {
+                        $filePath = $file->getRealPath();
+                        // extracting filename with substr/strlen
+                        $relativePath = substr($filePath, strlen($path) + 1);
+                        $zip->addFile($filePath, $relativePath);
+                    }
                 }
-            }
-            else
-            {
-                $flag=true;
-            break;
-            }
+                $zip->close();
+                $headers = array('Content-Type' => 'application/octet-stream');
+                $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip';
+                return response()->download($zip_file, $zip_new_name, $headers);
         }
-        if(!$flag) {
-            $zip->close();
-            $headers = array('Content-Type' => 'application/octet-stream');
-            $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip';
-            return response()->download($zip_file, $zip_new_name, $headers);
-        }
-        else {
-            Alert::flash("All departments are empty", "warning");
+        catch(\Exception $e){
+           Alert::flash("All departments are empty", "warning");
             return redirect()->back();
         }
@@ -166,27 +159,24 @@
         $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE);
         $path = Storage::disk('uploads')->path($department->location) . DIRECTORY_SEPARATOR;
-        $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
 
-        $filesInDept = $FileSystem->allFiles($path);
-
-        if(!empty($filesInDept)) {
-        foreach ($files as $file) {
-            if (!$file->isDir()) {
-                $filePath = $file->getRealPath();
-                // extracting filename with substr/strlen
-                $relativePath = substr($filePath, strlen($path) + 1);
-                $zip->addFile($filePath, $relativePath);
-            }
+        try{
+            $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
+            foreach ($files as $file) {
+                if (!$file->isDir()) {
+                    $filePath = $file->getRealPath();
+                    // extracting filename with substr/strlen
+                    $relativePath = substr($filePath, strlen($path) + 1);
+                    $zip->addFile($filePath, $relativePath);
+                }
+            $zip->close();
+            $headers = array('Content-Type' => 'application/octet-stream',);
+            $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $department->name . '.zip';
+            return response()->download($zip_file, $zip_new_name, $headers);
         }
-        $zip->close();
-        $headers = array('Content-Type' => 'application/octet-stream',);
-            $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $department->name . '.zip';
-        return response()->download($zip_file, $zip_new_name, $headers);
-        }
-        else{
+    }
+    catch(\Exception $e) {
             Alert::flash("This department has no files", "warning");
             return redirect()->back();
-        }
-
+    }
     }
 }
Index: app/Http/Controllers/Dashboard/FoldersController.php
===================================================================
--- app/Http/Controllers/Dashboard/FoldersController.php	(revision 1c17e70fdb646adb10dabb9aee5dbe8a5427853f)
+++ app/Http/Controllers/Dashboard/FoldersController.php	(revision 159e7df5cac7501076108bf1a80ef55c96981454)
@@ -284,9 +284,9 @@
         $path = Storage::disk('uploads')->path($folder->department->location . DIRECTORY_SEPARATOR . $folder->name);
 
-        $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
-
-        $filesInDoc = $FileSystem->allFiles($path);
-
-        if(empty(!$filesInDoc)) {
+        try {
+            $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path));
+
+            $filesInDoc = $FileSystem->allFiles($path);
+
             foreach ($files as $file) {
                 if (!$file->isDir()) {
@@ -300,11 +300,10 @@
             $headers = array('Content-Type' => 'application/octet-stream',);
             $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $folder->name . '.zip';
-                return response()->download($zip_file, $zip_new_name, $headers);
-        }
-        else {
+            return response()->download($zip_file, $zip_new_name, $headers);
+        }
+        catch (\Exception $e) {
             Alert::flash("This folder has no files", "warning");
             return redirect()->back();
         }
-
     }
 
