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

Today now in this blog I will show you how to count number of files in floder and remove all files in folder. if we are working on laravel framwork and also we want to count how many image or files in the folder and if need to print of front then you can do this with laravel “File” class. You know we can also count this in core PHP only by using glob() but if we are working on laravel then we have to use ‘File’ class library and then it will be easy and more flexible to use.

So if we also want to remove all the files Or images in any specific folder then we can delete by using “File” class function. Now sometimes we need to delete files in the folder that time we can do this on 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();

Read Also : How to Open Link in New Tab on Click in javascript ?

Thanks for read this, I hope it will you. You can also follow us onĀ Facebook.


About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →