Last active
September 7, 2015 12:22
-
-
Save joernroeder/155de158403c37c7f040 to your computer and use it in GitHub Desktop.
Returns an array with all filenames found in the given path filtered by the given extension (optional).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FilenameFilter; | |
// returns all filenames | |
String[] processFolder(String path) { | |
return processFolder(path, null); | |
} | |
// returns all filenames filtered by extension | |
String[] processFolder(String path, final String ext) { | |
java.io.File folder = new java.io.File(path); | |
if (ext == null) { | |
return folder.list(); | |
} | |
java.io.FilenameFilter extFilter = new java.io.FilenameFilter() { | |
public boolean accept(java.io.File dir, String name) { | |
return name.toLowerCase().endsWith("." + ext); | |
} | |
}; | |
return folder.list(extFilter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment