# Exclude type file from selectInput()?

**URL:** <https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719>\
**Category:** Coding Questions\
**Created:** [March 28, 2019, 12:01pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719 "2019-03-28T12:01:10Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [March 28, 2019, 12:01pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/1 "2019-03-28T12:01:10Z")

</div>

Is it possible to exclude a specific type file when we use `selectInput()` as seen in this image?

 ![10](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b2e6287e4a8d5bb880c67a1f7760055285cc87a9.png)

---

<div class="post-metadata">

**Author:** ![cansik](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/cansik/32/8815_2.png) [@cansik](https://discourse.processing.org/u/cansik)\
**Post date:** [March 28, 2019, 12:12pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/2 "2019-03-28T12:12:34Z")

</div>

Have you already google it? Second link shows this thread:

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/comment/10260/#Comment_10260)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [March 28, 2019, 12:54pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/3 "2019-03-28T12:54:39Z")

</div>

Thanks I don’t see this specific post, but I don’t understand, where I must pass this filter and how ?

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [March 28, 2019, 2:31pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/4 "2019-03-28T14:31:39Z")

</div>

there is a good example:

> [@File Listing Order](https://discourse.processing.org/t/file-listing-order/7148/23):
>
> When I need to code a very simple sketch, w/o any animations or even functions, I use what is so called “static sketch”. The standard 1 is called “interactive sketch”, in which we can have the callbacks setup() & draw(). More info on them here: [Processing.org/tutorials/overview/](http://Processing.org/tutorials/overview/) Here’s the my “static sketch” converted to “dynamic sketch”: grinning static final String PICS\_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp"; void setup() { final File dir = dataFile(""); printl…

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [March 28, 2019, 3:12pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/5 "2019-03-28T15:12:49Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 29, 2019, 5:52pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/6 "2019-03-29T17:52:22Z")

</div>

I believe that someone once implemented a file filter for selectInput, but I _think_ it was never merged. Perhaps use that code?

> <https://github.com/processing/processing/issues/272>

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](https://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html)

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [March 31, 2019, 8:22am UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/7 "2019-03-31T08:22:13Z")

</div>

So i continue my investigation on [stackoverflow](https://stackoverflow.com/questions/55439013/exclude-file-in-window-dialog-osx)  
because I’ve a feeling the solution to exclude type of file work only for input folder.

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![mrbbp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mrbbp/32/15313_2.png) [@mrbbp](https://discourse.processing.org/u/mrbbp)\
**Post date:** [September 13, 2023, 5:48am UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/8 "2023-09-13T05:48:13Z")

</div>

Hello, sorry i try to wakeup the subject.

i try to dev an app for playing with collage on picture for newbies and looking for a way to select extension file selectable in `selectInput()`.

I do not see any implementation, in my SearchEngines, of the third parameter `file` in the `selectInput(prompt, callback, file)`!  
Does anyone have an answer to this old topic?

the first java code open ugly java windows, not OS specific windows.  
So is there a way and an example code, in Processing, to select extension of `inputSelect()` as OS purpose since 40 years?

regards

---

<div class="post-metadata">

**Author:** ![Stanlepunk](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/stanlepunk/32/11509_2.png) [@Stanlepunk](https://discourse.processing.org/u/Stanlepunk)\
**Post date:** [September 13, 2023, 8:45am UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/9 "2023-09-13T08:45:26Z")

</div>

I work on your subject and I develop something can help you… I hope

> <https://github.com/knupel/Rope/blob/7d802ca751be0580623b94030a0ab489d4ae153e/src/rope/tool/file/R_Input.java#L154>

---

<div class="post-metadata">

**Author:** ![mrbbp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mrbbp/32/15313_2.png) [@mrbbp](https://discourse.processing.org/u/mrbbp)\
**Post date:** [September 14, 2023, 3:20pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/10 "2023-09-14T15:20:49Z")

</div>

> [@Stanlepunk](#):
>
> I work on your subject and I develop something can help you… I hope

Well Stan, i’m not sure to understand how to use your code.  
do i have to copy the `selectInput` function (i think i need more)  
or do i import your code with an url?  
sorry, for this question.  
Im’ not as good as you think 😉

regards

---

<div class="post-metadata">

**Author:** ![mrbbp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mrbbp/32/15313_2.png) [@mrbbp](https://discourse.processing.org/u/mrbbp)\
**Post date:** [September 14, 2023, 3:36pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/12 "2023-09-14T15:36:15Z")

</div>

@Stanlepunk ok i downloaded the rope.zip and add it to my Librairies  
I tried the select\_input.pde example but the sketch block without error.

i’m working on macos ventura 13.5.2 with procesisng 4.2 and 4.3

i tried the `folder_explore.pde` and if i understand well it suppose to show only jpeg file… the jpeg file are greyed too.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 14, 2023, 5:51pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/13 "2023-09-14T17:51:47Z")

</div>

The full function header for Processing’s `selectInput` method is  
`selectInput(prompt, callback, file, callbackObject)`

Although the first two parameters are well documented the optional 3rd and 4th are not 😞

Digging into the source code I believe that the following is true

- `file` :- is the default file selection. So if provided the dialog box will open with this file selected
- `callbackObject`: the object that contains the callback method to be executed when the dialog box closes. If none provided then it will look inside your sketch for it.

Processing does not appear to provide a mechanism to filter by file type which again is disappointing.

Th easiest solution would to use the G4P library. For instance the statement -

`fname = G4P.selectInput("Input Dialog", "png,gif,jpg,jpeg", "Image files");`

opens a dialog box where files with the extension `png gif jpg` or `jpeg` can be selected.

Where `fname` is of type String and will hold the full path and filename for the selected file. If the dialog is cancelled then `fname` is `null`

Unlike Processing the `select` methods in G4P are modal which means that the sketch execution stops until the dialog box closes, so no callback function needed.

---

<div class="post-metadata">

**Author:** ![mrbbp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mrbbp/32/15313_2.png) [@mrbbp](https://discourse.processing.org/u/mrbbp)\
**Post date:** [September 15, 2023, 3:41pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/14 "2023-09-15T15:41:08Z")

</div>

Hello Quark

thanks for the answer

```auto
import g4p_controls.*;
String fname;

void setup() {
  fname = G4P.selectInput("Bonjour", "png,gif,jpg,jpeg", "Image files");
  println(fname);
}

void draw() {
  
}

```

it works well as expected, but i do not find any doc for this lib.  
The three parameters are “strings”, where can i place the start point for file looking?  
the first and third params are invisible in MacOS (ventura) system window…  
It seems to remember my last folder path but not the default skechtPath from where is my sketch.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [September 15, 2023, 4:45pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/15 "2023-09-15T16:45:49Z")

</div>

Hi @mrbbp,

> [@mrbbp](#):
>
> but i do not find any doc for this lib.

[http://www.lagers.org.uk/g4p/ref/classg4p\_\_controls\_1\_1\_g4\_p.html#a34b5f1cceb46ea8f23de801c7aced033](http://www.lagers.org.uk/g4p/ref/classg4p__controls_1_1_g4_p.html#a34b5f1cceb46ea8f23de801c7aced033)

Cheers  
— mnse

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 15, 2023, 4:51pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/16 "2023-09-15T16:51:55Z")

</div>

Thanks to @mnse for beating me to it 😀

> [@mrbbp](#):
>
> the first and third params are invisible in MacOS (ventura) system window…

What actually gets shown in the dialog box depends on the OS, sometimes these are shown and sometimes not.

> [@mrbbp](#):
>
> It seems to remember my last folder path but not the default skechtPath from where is my sketch.

This is the default situation in most OSs and what you would expect in most applications e.g. MS Word

> [@mrbbp](#):
>
> where can i place the start point for file looking?

The method takes a fourth parameter for the starting point - see documentation in link provided by mnse

---

<div class="post-metadata">

**Author:** ![mrbbp](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mrbbp/32/15313_2.png) [@mrbbp](https://discourse.processing.org/u/mrbbp)\
**Post date:** [September 18, 2023, 6:47am UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/17 "2023-09-18T06:47:09Z")

</div>

thanks for @mnse for pointing the doc and particulary @quark for the works.

i complete the script to start in the sketch folder.

```auto
import g4p_controls.*;
String fname;

void setup() {
  fname = G4P.selectInput("unseen in MacOS", "png,gif,jpg,jpeg", "unseen in MacOS", sketchPath("") );
  println(fname);
}

void draw() {
  
}

```

regards

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [September 18, 2023, 9:12am UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/18 "2023-09-18T09:12:52Z")

</div>

Can I set also the path the dialog opens in?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [September 18, 2023, 5:03pm UTC](https://discourse.processing.org/t/exclude-type-file-from-selectinput/9719/19 "2023-09-18T17:03:25Z")

</div>

Yes, by startFolder parameter.
