How can I know the number of images inside a particular file in assets What should I use?
Asked
Active
Viewed 951 times
-1
-
A particular file, or a particular folder? – TheWanderer Dec 01 '18 at 16:52
-
There is no difference I have a file in my project and inside it I want to know the number of images using the code – Taha Sami Dec 01 '18 at 16:53
-
Number of images inside what? What type of file holds multiple images? – TheWanderer Dec 01 '18 at 16:54
-
inside assets folder for example assets/Images/here all Images – Taha Sami Dec 01 '18 at 16:55
2 Answers
1
One line code
Int no_of_imgs = getResources().getAssets().list("foldar_name").length;
This works inside activity or fragment class.

Mayank Kumar Chaudhari
- 16,027
- 10
- 55
- 122
1
this code count android assets folder all files also containing in subfolders
private int countAssetFiles(String path) {
int filesCount = 0;
String [] list;
try {
list = getAssets().list(path);
if (list.length > 0) {
for (String file : list) {
// if there is a subfolder this line add count of that subfolder to total count else add 1(one file)
filesCount += listAssetFiles(path + "/" + file);
}
}
} catch (IOException e) {
//path is a file
return 1;
}
return filesCount;
}
by below code you can get all files count in asset folder
int allFilesCount = countAssetFiles("");
if you want to get certain folder files in asset use this
int filesInSubFolder = countAssetFiles("/subFolderName");

Mehdi Varse
- 271
- 1
- 15