Add a file format selection option.

I have updated the code to allow the user to pass a what ever number of file formats they wish to look for in a folder.
This commit is contained in:
efrick 2021-08-17 12:55:53 -04:00
parent 9fe9469441
commit 0bfb18af09

View File

@ -35,6 +35,13 @@ public class Picture_Lister {
System.exit(0);
}
String picture_dir = args[0];
String[] file_format = {".png"};
if (args.length > 1){
for(int i = 1; i < args.length; i++){
file_format[i-1] = args[i];
}
}
System.out.println(picture_dir);
//Creating a File object for directory
File directoryPath = new File(picture_dir);
@ -43,7 +50,7 @@ public class Picture_Lister {
@Override
public boolean accept(File dir, String name) {
if(name.lastIndexOf('.')>0) {
String[] exclude = {".png",".jpg"};
String[] include = file_format;
// get last index for '.' char
int lastIndex = name.lastIndexOf('.');
@ -51,7 +58,7 @@ public class Picture_Lister {
String str = name.substring(lastIndex);
// match path name extension
for (String place_holder : exclude) {
for (String place_holder : include) {
if (str.equalsIgnoreCase(place_holder)) {
return true;
}