# SelectFolder(), SelectInput(), SelectOutput() Questions

**URL:** <https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974>\
**Category:** Coding Questions\
**Created:** [August 22, 2024, 11:16am UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974 "2024-08-22T11:16:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thundercat](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@Thundercat](https://discourse.processing.org/u/Thundercat)\
**Post date:** [August 22, 2024, 11:16am UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974/1 "2024-08-22T11:16:23Z")

</div>

Hi, I would like to implement the `SelectFolder()`, `SelectInput()`, and `SelectOutput()` methods but also specify the folder that they open to.

I’ve spent a lot of time googling this and trying to understand it, but haven’t found a solution. I saw a GitHub discussion from 11 years ago about this, but it seems nothing was done to implement any of it.

It’s important for ease of use that the dialogs open to a specific directory.

Is there any way to do this?

Also, is there any way to filter the `SelectInput()` & `SelectFolder()` methods to only show files of a certain type, say, of text files?

Thank you,

Mike

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 23, 2024, 12:00am UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974/2 "2024-08-23T00:00:32Z")

</div>

Hell @Thundercat,

This will open to a specified directory:

```Java
// Code from these links was modified:
// https://forum.processing.org/beta/num_1140487204.html
// https://stackoverflow.com/questions/13516829/jfilechooser-change-default-directory-in-windows

import javax.swing.*;
PImage img;
boolean loaded = false;

void setup()
  {
  size(500, 500);
  }

void draw()
  {
  if(loaded) 
    {
    image(img, 0, 0);  
    println(img.width);
    }
  }

void mousePressed()
  {
  launchChooser();
  }

void launchChooser()
  {
  SwingUtilities.invokeLater(new Runnable()
    {
    public void run()
      {
      loaded = false;
      try 
        {
        JFileChooser fc = new JFileChooser();
        fc.setCurrentDirectory(new File("D:/Users/GLV/Pictures/"));
        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) 
          {
          File file = fc.getSelectedFile();
          //String name = file.getName().toLowerCase();
          //if (name.endsWith(".png") || name.endsWith(".gif")) 
          // {
            img = loadImage(file.getAbsolutePath());
            println(file.getAbsolutePath());
            loaded = true;
            println(loaded, img.width, img.height);
            //}
          }
        }
      catch (Exception e) 
        {
        e.printStackTrace();
        }
      }
    }
    );
  }

//void imageChosen() 
// {
// image(img, 0, 0, width, height);
// }

```

I gleaned some insight from the source code here that helped in my search for a solution:  
_[processing4/core/src/processing/core/PApplet.java at main · benfry/processing4 · GitHub](https://github.com/benfry/processing4/blob/main/core/src/processing/core/PApplet.java)_

`:)`

---

<div class="post-metadata">

**Author:** ![Thundercat](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@Thundercat](https://discourse.processing.org/u/Thundercat)\
**Post date:** [August 23, 2024, 12:31am UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974/3 "2024-08-23T00:31:19Z")

</div>

Hi @glv, amazing!

I totally appreciate you taking the time to share this!

It works!

I also modified it a little bit so it will work to select a directory instead of just a folder:

```Java
// Code from these links was modified:
//https://forum.processing.org/beta/num_1140487204.html
//https://stackoverflow.com/questions/13516829/jfilechooser-change-default-directory-in-windows

import javax.swing.*;
PImage img;
boolean loaded = false;

void setup()
  {
  size(500, 500);
  }

void draw()
  {
  if(loaded) 
    {
    image(img, 0, 0);  
    println(img.width);
    }
  }

void mousePressed()
  {
  launchChooser();
  }

void launchChooser()
  {
  SwingUtilities.invokeLater(new Runnable()
    {
    public void run()
      {
      loaded = false;
      try 
        {
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fc.setCurrentDirectory(new File("/Users/Username/Documents/SomeFolder"));
        fc.setDialogTitle("Select a folder");
        int returnVal = fc.showOpenDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) 
          {
          File file = fc.getSelectedFile();
          //String name = file.getName().toLowerCase();
          //if (name.endsWith(".png") || name.endsWith(".gif")) 
          // {
            //img = loadImage(file.getAbsolutePath());
            println(file.getAbsolutePath());
            //loaded = true;
            //println(loaded, img.width, img.height);
            //}
          }
        }
      catch (Exception e) 
        {
        e.printStackTrace();
        }
      }
    }
    );
  }

```

What about selectOutput() command to select a file?

I’m wondering why processing hasn’t done anything in 11 years with this - it seems like an important thing to have as part of the language!

I totally appreciate your time, so again, THANK YOU for your expertise!!!

Mike

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 23, 2024, 8:22am UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974/4 "2024-08-23T08:22:32Z")

</div>

> [@Thundercat](#):
>
> I totally appreciate your time, so again, THANK YOU for your expertise!!!

You are welcome!  
You get good at finding solutions with experience, patience and persistence.  
And I do enjoy the challenges!

Java is new to me (was?) and it can be a challenge at times.

See also:

> [@How to make the selectFolder() function open using a default path](https://discourse.processing.org/t/how-to-make-the-selectfolder-function-open-using-a-default-path/34369/7):
>
> Hi I know this is an old thread, but how did you do this? I was about to post this exact question. I looked at the references you shared but cannot see how to accomplish it… Thanks, Mike

`:)`

---

<div class="post-metadata">

**Author:** ![Thundercat](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@Thundercat](https://discourse.processing.org/u/Thundercat)\
**Post date:** [August 23, 2024, 11:24am UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974/5 "2024-08-23T11:24:18Z")

</div>

You make this forum a better place.

Thank you SO MUCH!

Mike

---

<div class="post-metadata">

**Author:** ![Thundercat](https://avatars.discourse-cdn.com/v4/letter/t/dbc845/32.png) [@Thundercat](https://discourse.processing.org/u/Thundercat)\
**Post date:** [August 23, 2024, 12:37pm UTC](https://discourse.processing.org/t/selectfolder-selectinput-selectoutput-questions/44974/6 "2024-08-23T12:37:00Z")

</div>

PS I didn’t know which post to mark as the solution - the link to your other solution is great too! And I like it better because it’s a bit simpler.

thank you again!!

Mike
