File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
app/src/processing/app/helpers Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 11package processing .app .helpers ;
22
33import java .io .*;
4+ import java .util .ArrayList ;
45import java .util .Arrays ;
56import java .util .List ;
67import java .util .Random ;
@@ -188,4 +189,30 @@ public static String readFileToString(File file) throws IOException {
188189 }
189190 }
190191 }
192+
193+ /**
194+ * Recursively find all files in a folder with the specified extension
195+ *
196+ * @param folder
197+ * @param extensions
198+ * @return
199+ */
200+ public static List <File > listAllFilesWithExtension (File folder , String ... extensions ) {
201+ List <File > result = new ArrayList <File >();
202+ for (File file : folder .listFiles ()) {
203+ if (file .isDirectory ()) {
204+ result .addAll (listAllFilesWithExtension (file , extensions ));
205+ continue ;
206+ }
207+
208+ for (String ext : extensions ) {
209+ if (file .getName ().endsWith (ext )) {
210+ result .add (file );
211+ break ;
212+ }
213+ }
214+ }
215+ return result ;
216+ }
217+
191218}
You can’t perform that action at this time.
0 commit comments