0

Getting all particular files in directory and adding them to ArrayList

How to get all "Files" containing word "pic" and "vids" in a directory and subdirectories and add them into a ArrayList

1st Mar 2019, 4:01 AM
Maninder Singh
Maninder Singh - avatar
1 ответ
+ 6
Java.io.File contains the .getName() method which allows you to read a name as String. You can then use the .contains() method to check if the returned string contains "pic" or "vids". Assuming you have a list of files, you iterate through each of them and check: if (myFile.getName().contains("pic") || myFile.getName().contains("vids")) myArrayList.add(myFile); If you need help listing all the files in the directory and also subdirectory, try referring to the example in this link: https://stackoverflow.com/questions/14676407/list-all-files-in-the-folder-and-also-sub-folders
1st Mar 2019, 4:08 AM
Fermi
Fermi - avatar