I am trying to use FileDialog to select multiple files. I have noticed that the file names you retrieve with FileDialog::getFileNames() have no path. So I tried to combine them with FileDialog:getFilterPath, which returns a single string. However, in the "Recent" tab, each file has a different path! Is FileDialog not made with this in mind? How to proceed?
Here is code so that you can see it for yourself quickly:
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Shell;
public class FileDialogRecentTest {
public static void main (String [] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setText("FileDialogRecentTest");
shell.open ();
// Trying to get full paths from GTK's "Recent" tab, in which all files have different directories
FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI);
dialog.open();
String[] fileNames = dialog.getFileNames();
// But .getFilterPath() only returns the first selected file's path! It's the same for all files!
String directory = dialog.getFilterPath();
// Print full paths of all files
for (String fileName : fileNames)
System.out.println(directory + '/' + fileName);
while (!shell.isDisposed ()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();
}
}