Laravel - How to count number of files in folder and remove all files in folder example?

By Hardik Savani | January 13, 2016 | Category : Laravel

you are working on laravel framwork and you want to count how many image or files in folder and print of front then you can do with laravel "File" can also count in core PHP by using glob() but if you are working on laravel then you have to use 'File' class library and it is easy and more flexible to use.

If you also want to remove all the files Or images in specific folder then you can delete by using "File" class function. sometimes we need to delete files in the folder. that way:

use Input;

use File;

class HomeController extends AdminController


public function countImages() {

$files = File::files(public_path('textPrintImage'));

$filecount = 0;

if ($files !== false) {

$filecount = count($files);


return $filecount;


public function removeImages() {


return back();



Try this...

Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.