Use path of selected folder for next selection as default value

Hello , i’m totally new to processing - i had one huge but sure simple topic.
I need to modify a processing program with many subfiles.
It had a gui - for this is g4p_controls used.
in the gui i can open data files.
It would usefull if not everytime the default path is active (user documents folder) instead it woul be much better if another file location is selected, to save the path to directory and use it as default path for next time.
Could someone explain me how this could be implemented?
The file is selected by select input function.

It would be very nice if

  1. someone could explain me how to save the directory as default path in a file.
  2. how the file could be used to select a this path as start directory if the user open next time a data file.

any explanation would be helpfull.

Best regards,

I had search some times

1 Like

Hi El_Paco,

You can save the path that you want in a file. For that I advise you to go have a look at the Output->Files section of the references!

Then when you start your sketch you just need to open that file, read the path and apply it to your control.

Hi jb4x, many thanks for the answer.
At this time i can save the absolute path with the selected file in a file.
How can i cut the filename from my saved string?
the next important step would be to read it and to say my control please start the select folder operation in this default folder…

but this i did’nt know.

Best regards, El_Paco

Post here what you have done so far, it will be easier for us to help you!

in the gui we have a function to select a file for data import:

public void load_data_button_click(GButton source, GEvent event) {   if (event == GEvent.CLICKED) {
    selectInput("Select File to import: ", "loadData");

as next we have the function loadData:

voidloadData(File selection) { 

  if (selection == null) { // no path
  } else { // path selected
    String[] paths = {selection.getAbsolutePath()};
    println(" User selected "+ selection.getAbsolutePath());
    folder = new File(selection.getAbsolutePath());
    saveStrings(AppDataPath + "/userPaths.txt", paths);

… other code.

sorry i could not share other code

  1. is to much
  2. not allowed by company rules

i have the location and name of last file saved in userPaths.txt

but how can i use this to pass it as preference directory if user want to load new data set .

i have seen Java has a posibility to define preference path but how to use it in my processing code ?
see this link:


Preferences pref = Preferences.userRoot();

// Retrieve the selected path or use
// an empty string if no path has
// previously been selected
String path = pref.get("DEFAULT_PATH", "");

JFileChooser chooser = new JFileChooser();

// Set the path that was saved in preferences
chooser.setCurrentDirectory(new File(path));

int returnVal = chooser.showOpenDialog(null);

if (returnVal == JFileChooser.APPROVE_OPTION)
    File f = chooser.getSelectedFile();

    // Save the selected path
    pref.put("DEFAULT_PATH", f.getAbsolutePath());

but i’m unable to integrate this code in processing because functions of java ( setCurrentDirectory) are unknown in processing .

also i found a page which will solve eventually my problem but if i understand it correct it will modify java function - i thing this would not be practicable - because everytime if on the pc the java ist updated (which is done sometimes by IT over nigth) this wouldnt work.

the link to solution by modify

would it be possible to do something like this in processing without to modify

best regards,
El Paco