Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count the number of files in a folder in external storage?

Tags:

android

I wanted to know the count of my downloaded files in a folder saved in my external strorage

like image 351
rubberdont Avatar asked Dec 09 '22 07:12

rubberdont


2 Answers

Try this,and replace yourfolder with your actual folder name

File dir = new File(Environment.getExternalStorageDirectory() + "/yourfolder");
File[] files = dir.listFiles();
if (files != null) {
   int numberOfFiles = files.length;
}
like image 199
Giru Bhai Avatar answered May 23 '23 06:05

Giru Bhai


     File sdCardRoot = Environment.getExternalStorageDirectory();
        File yourDir = new File(sdCardRoot, "New Folder");
int counter = 0;
        for (File f : yourDir.listFiles()) {
            if (f.isFile())


        {

            String name = f.getName();
    counter++;
                    Log.i("file names", name);


        }
    Log.d("TAG", "File count: " + counter);
        }

Try this. I didn't try this before but it's worth a try. Cheers!

like image 39
JayR Avatar answered May 23 '23 06:05

JayR