Is there a way to have selectInput() select files in the sketchbook folder:data folder?

selectInput("Select a file : ","fileSelected"); defaults to my Documents folder but not to my Processing folder, which is on Dropbox. Is there a way to have selectInput() select files in the sketchbook folder:data folder?

Answers

  • edited August 2016

    From selectInput()'s reference example, using its overloaded version w/ 3 parameters + dataFile():

    https://Processing.org/reference/selectInput_.html

    void setup() {
      selectInput("Select a file to process:", "fileSelected", dataFile("name_of_file"));
    }
    
    void fileSelected(final File selection) {
      if (selection == null)
        println("Window was closed or the user hit cancel.");
      else
        println("User selected " + selection.getPath());
    }
    
  • This gets me almost there. I can manually enter the file path all the way to the file inside the current MyApp.pde/data folder but that changes with each revision. If I can find the variable that holds the current running filename of the MyApp.pde, I'm home free.

  • ... If I can find the variable that holds the current running filename of the MyApp.pde, ...

    "current running filename"? What do you mean by that? :-/

  • I found it in another post. Life is good!

    // forum.processing.org/two/discussion/12572/sketchpath-in-the-settings // 2015-Sep-18

    String AppSketchPath, AppDataPath;

    void settings() { size(800, 200, JAVA2D); noLoop(); AppSketchPath = sketchPath(); AppDataPath = dataPath(""); }

    void setup() { getSurface().setTitle(AppDataPath); String[] paths = { AppSketchPath, AppDataPath }; saveStrings(AppDataPath + "/Paths.txt", paths); }

  • The full pathname of the currently running sketch.

  • edited August 2016 Answer ✓

    https://forum.Processing.org/two/discussion/15473/readme-how-to-format-code-and-text

    You've asked for "running filename", not "running pathname". But whatever... :-\"

    Besides those 2 you've found out, there are also their corresponding versions which returns a File object instead of a String one:

    1. sketchPath() -> sketchFile().
    2. dataPath() -> dataFile().

    As you can see, in my posted example, I've used dataFile() as selectInput()'s 3rd argument. >-)

Sign In or Register to comment.