Hi guys… been racking my brains over this. I wanted to do a sort of extension filtering much like in the pic here… where the user can select the file extension or type eg: jpg, png, avi, mp4, etc
I went down the route of FilenameFilter() before realizing that it only does that under the hood so to speak.
How may I go about it visually to get it represented like in the picture? Thanks!
import java.io.File;
import java.io.FilenameFilter;
String selectedAbsolutePath, selectedFolderName;
void setup() {
size(300, 300);
}
void draw() {
}
void mousePressed() {
println("Directory selection is pressed");
OpenDirectory();
}
void OpenDirectory() {
selectFolder("Select a folder to process:", "setDirectoryPath");
}
void setDirectoryPath(File selection) {
if (selection != null) {
selectedAbsolutePath = selection.getAbsolutePath();
selectedFolderName = selection.getName();
println(selectedAbsolutePath);
println(selectedFolderName);
try {
// Create a file object
File f = new File(selectedAbsolutePath);
// Create a FilenameFilter
FilenameFilter filter = new FilenameFilter() {
boolean accept(File f, String name)
{
return name.endsWith(".jpg");
}
};
// Get all the names of the files present
// in the given directory
// and whose names end with ".jpg"
File[] files = f.listFiles(filter);
println("Files are:");
// Display the names of the files
for (int i = 0; i < files.length; i++) {
println(files[i].getName());
}
}
catch(Exception e) {
System.err.println(e.getMessage());
}
} else {
println("Windows was or user hit cancel.");
}
}