I wanted to know the count of my downloaded files in a folder saved in my external strorage
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;
}
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With