# SelectInput: I like to tell it the folder to use?

**URL:** <https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703>\
**Category:** Coding Questions\
**Created:** [August 30, 2019, 12:27pm UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703 "2019-08-30T12:27:15Z")\
**Posts on this page:** 10\
**Page:** 1

<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:** [August 30, 2019, 12:27pm UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/1 "2019-08-30T12:27:15Z")

</div>

Hello all,

I‘d like to tell selectInput() which folder and file extension to use:

```auto
File file1= new File( sketchPath(”“) + ”*.txt“);

selectInput(”...“, ”...“, file1);

```

Doesn’t work. It starts with the Desktop Folder instead (and not in sketch path folder).

(Sorry for the wrong „“, my iPhone…)

What do I have to change?

Win 10.

Thank you!

Chrisir

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 31, 2019, 4:47am UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/2 "2019-08-31T04:47:55Z")

</div>

Limited research but probly these next links could help:

- [Goto in this post](https://forum.processing.org/two/discussion/17982/is-there-a-way-to-have-selectinput-select-files-in-the-sketchbook-folder-data-folder)

- [The docs which you might have seen (nothing about extensions)](https://processing.org/reference/selectInput_.html)

- Checking the [source code](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java#L50), you need to check _JFileChooser_ and probly _FileChooser_’s documentation and use those libraries directly if it fits your use case requirements.

Kf

---

<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:** [August 31, 2019, 9:07am UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/3 "2019-08-31T09:07:45Z")

</div>

Actually

`selectInput` `(` `"Select a file to process:"` `,` `"fileSelected"` `, dataFile(` `"*.txt"` `));`

did the trick.

Remaining problem is that the load dialog is not in the foreground in Win 10 but hidden.

Any ideas?

---

<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:** [August 31, 2019, 11:45pm UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/4 "2019-08-31T23:45:39Z")

</div>

> [@Chrisir](#):
>
> the load dialog is not in the foreground

This sounds like a bug worth reporting. Is that behind a PDE sketch window, or is it from an exported application?

---

<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:** [September 1, 2019, 1:00am UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/5 "2019-09-01T01:00:27Z")

</div>

in Win 10 / processing 3.5.3. /  
called from a keyPressed()  
no problem

 ![processing_fileload_keyR](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/e/e9804f30587fb5e568fce4c58a8ed3759302cc19.png)

but yes usually thing like  
JOptionPane.showInputDialog  
tend to be behind the canvas window GRRR

different example:

```auto
// https://discourse.processing.org/t/file-listing-order/7148/23
// https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/3

// as started from load display image i have a sub dir /data/ with a data\moonwalk.jpg

static final String PICS_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp";
File dir;
String[] imagePaths = {};
int imagesFound = 0;
boolean havefile = false;
PImage img;

void filedata() { // @GoToLoop
  dir = dataFile("");
  println(dir);
  if (dir.isDirectory()) {
    imagePaths = listPaths(dir.getPath(), "files", "recursive", PICS_EXTS);
    imagesFound = imagePaths.length;
  }
  printArray(imagePaths);
  println("Found", imagesFound, "image(s)");
}

void setup() {
  size(300,300);
  filedata();
  println("use: key [r] for file open dlg\n or key [0 (...x]) for load from array");
}

void draw() {
  if ( havefile ) image(img,0,0); //,width,height
}

void keyPressed() {
  if ( key == 'r') {
    selectInput("open picture: ", "fileSelected", dataFile(PICS_EXTS));
  }
  if ( key == '0') {
    String thefile = imagePaths[0];
    println("you selected: key ["+key+"] "+thefile);
    img = loadImage(thefile);
    havefile = true;
  }
}

void fileSelected(final File sel) {
  if (sel != null) {
    String thefile = sel.getPath();
    println("you selected: "+thefile);
    img = loadImage(thefile);
    havefile = true;
  }
}

```

---

<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 1, 2019, 6:44pm UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/6 "2019-09-01T18:44:26Z")

</div>

Thanks a lot everyone!

---

<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 20, 2019, 3:03pm UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/7 "2019-09-20T15:03:17Z")

</div>

I have to say, sometimes it works. It seems to store the last directory implicitly. So often it looks like it works but it doesn’t.

It doesn’t really take the directory from the file I give to selectInput(). Seems to be a bug.

This is the core line for me :

```auto
selectInput("open picture: ", "fileSelected", dataFile(PICS_EXTS));

```

I understand this line:

```auto
static final String PICS_EXTS = "extensions=,png,jpg,jpeg,gif,tif,tiff,tga,bmp,wbmp";

```

How would I tell it the folder as well?

Thanks!

Chrisir

---

<div class="post-metadata">

**Author:** ![markcosmic](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@markcosmic](https://discourse.processing.org/u/markcosmic)\
**Post date:** [December 12, 2022, 12:23am UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/8 "2022-12-12T00:23:36Z")

</div>

I know you posted this back in 2019, but I thought I’d add a little something to it.  
I discovered it on accident. If you add “…:” to dataFile(_.txt); as in  
`selectInput(“Select a file to process:”, “fileSelected”, dataFile(" …:_.txt")); (2 or 3 dots/periods and a colon)  
the next time you use selectInput(), it will start the folder you last used. I don’t know why this works. I can’t find any information about it, but it works

---

<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:** [December 12, 2022, 9:52am UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/9 "2022-12-12T09:52:44Z")

</div>

thanks for coming back to me!

In my experience it will **always** start the folder you last used (not only with your trick) - which is a bug because it should use the folder you tell it to use.

---

<div class="post-metadata">

**Author:** ![markcosmic](https://avatars.discourse-cdn.com/v4/letter/m/ecc23a/32.png) [@markcosmic](https://discourse.processing.org/u/markcosmic)\
**Post date:** [December 19, 2022, 7:47pm UTC](https://discourse.processing.org/t/selectinput-i-like-to-tell-it-the-folder-to-use/13703/10 "2022-12-19T19:47:13Z")

</div>

> [@markcosmic](#):
>
> _`selectInput(“Select a file to process:”, “fileSelected”, dataFile(" …:_.txt"))

For me, selectInput(“Select a file to process:”, “fileSelected”, dataFile(" \* .txt")), always defaulted to the sketch data folder each time it was called. Granted, I can hard code a default folder, but that may not work for everyone nor every sketch. For instance, choosing a music folder. I discovered this while making a video for my YT channel “Mark Loves Coding” I’ve been coding a random music player based on a question I responded to on this forum. As the sketch evolves I eventually started using the selectInput() function. That is when I started to try to figure out why that function would not remember the last folder I was looking in. As a windows user I noticed that some apps do remember the last folder you were in and some don’t. But not Processing sketches using the selectInput() function. That said, rather than call it a bug, just add what I discovered to the documentation. I mean, why not, it works. Cheers
