From 0bfb18af0909f9ef7711da26d09d85cc6b527bfd Mon Sep 17 00:00:00 2001 From: efrick Date: Tue, 17 Aug 2021 12:55:53 -0400 Subject: [PATCH] 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. --- src/picture_lister/Picture_Lister.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/picture_lister/Picture_Lister.java b/src/picture_lister/Picture_Lister.java index e3bc43b..861dce6 100644 --- a/src/picture_lister/Picture_Lister.java +++ b/src/picture_lister/Picture_Lister.java @@ -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; }