Is it possible to exclude a specific type file when we use selectInput()
as seen in this image?
Have you already google it? Second link shows this thread:
Thanks I donât see this specific post, but I donât understand, where I must pass this filter and how ?
void setup() {
String prompt = "Select a file to process:";
String callback = "fileSelected";
selectInput(prompt, callback);
// selectInput(prompt, callback)
// selectInput(prompt, callback, file)
// selectInput(prompt, callback, file, callbackObject)
// selectInput(prompt, callbackMethod, file, callbackObject, parent, sketch)
//selectInput(prompt, callbackMethod, file, callbackObject, parent)
}
void fileSelected(File selection) {
if (selection == null) {
println("Nothing");
} else {
println("Input default path is:" +selection.getAbsolutePath());
println(selection.getAbsolutePath());
}
}
import java.io.FilenameFilter;
static final String[] exts = {
".gif", ".png", ".jpeg", ".jpg"
};
static final FilenameFilter pictsFilter = new FilenameFilter() {
boolean accept(File dir, String name) {
name = name.toLowerCase();
for (int i = exts.length; i-- != 0;) if (name.endsWith(exts[i])) return true;
return false;
}
};
static final File[] getFolderContent(File dir) {
return dir.listFiles(pictsFilter);
}
there is a good example:
Thx, but itâs not what I want. I need to open a window to select the file with selectInput()
but excludes the files not concerned like on the pics show on the top of topics, where the files is gray light when itâs not possible to select.
By example when I use Photoshop and open file i cannot selected file from Indesign.
Make sens ?
Or maybe i donât understand the example you show me ?
I believe that someone once implemented a file filter for selectInput, but I think it was never merged. Perhaps use that code?
You can also make your own java swing FileChooser with a filter as per this tutorial:
https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html
So i continue my investigation on stackoverflow
because Iâve a feeling the solution to exclude type of file work only for input folder.
void setup() {
selectFolder("Select a folder to process:", "folderSelected");
}
void folderSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
printArray(getFolderContent(selection));
}
}
import java.io.FilenameFilter;
static final String[] exts = { ".gif", ".png", ".jpeg", ".jpg", ".tiff", ".tif"};
static final FilenameFilter pictsFilter = new FilenameFilter() {
boolean accept(File dir, String name) {
name = name.toLowerCase();
for (int i = exts.length; i-- != 0;) {
if (name.endsWith(exts[i])) {
return true;
}
}
return false;
}
};
static final File[] getFolderContent(File dir) {
return dir.listFiles(pictsFilter);
}