Search code examples
javaswtopenfiledialogfiledialog

How to choose a folder to use for save in SWT?


I want to take folder path from user by using FileDialog. When user create a new folder then choose it and click "open", the folder open to choose new files in it. but, I want to take path of the choosen new folder without open it. My example code is below:

// File standard dialog
    FileDialog fileDialog = new FileDialog(shell);
    // Set the text
    fileDialog.setText("Select File");
    // Set filter on .txt files
    fileDialog.setFilterExtensions(new String[] { "*.txt" });
    // Put in a readable name for the filter
    fileDialog.setFilterNames(new String[] { "Textfiles(*.txt)" });
    // Open Dialog and save result of selection
    String selected = fileDialog.open();
    System.out.println(selected);

Can anybody give some advice about it? Thank you.


Solution

  • If you want to let the user choose a directory you can use the DirectoryDialog instead of a FileDialog.