How to make the selectFolder() function open using a default path

Interesting thing…I modified @glv’s example, hoping to be able to use it to import a file from a certain folder.

But it works intermittently. If I run it and press enter, it goes to the parent folder. Then if I cancel and hit enter, it goes to the exact folder.

If I hit enter again, it goes to the parent, and if I cancel and hit enter, it goes to the exact folder…

over and over…

why?

here’s the code:

//import java.io.*;  //import java.io.File; already imported by Processing!

File a = new File("/Users/UserName/Documents/Processing/SceneEditorV1_1_01/Backups"); // The folder must exist!

void setup() {
  size(200, 200);
  //selectFolder("Select a folder to process:", "folderSelected");
  
  //selectFolder(prompt, callbackMethod, defaultSelection, callbackObject, parentFrame)
  //selectFolder("Select a folder to process:", "folderSelected", a);
}

void folderSelected(File selection) {
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
  } else {
    println("User selected " + selection.getAbsolutePath());
  }
}

void draw()
  {
  }

void keyPressed()
  {
  selectInput("Select a backup file:", "folderSelected", a);  
  }

Anyone can see any reason it would go back and forth from parent to exact folder, over and over?

1 Like