diff --git a/src/main/java/net/sf/jabref/gui/FileDialog.java b/src/main/java/net/sf/jabref/gui/FileDialog.java index 07f4a619b94..84ec46b82d6 100644 --- a/src/main/java/net/sf/jabref/gui/FileDialog.java +++ b/src/main/java/net/sf/jabref/gui/FileDialog.java @@ -2,6 +2,7 @@ import java.awt.Component; import java.io.File; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; @@ -59,7 +60,10 @@ public FileDialog(Component parent, String dir) { public FileDialog(Component parent, Path dir) { Objects.requireNonNull(dir, "Directory must not be null"); - + //Dir must be a folder, not a file + if (!Files.isDirectory(dir)) { + dir = dir.getParent(); + } fileChooser = new FileChooser(); configurationBuilder = new FileDialogConfiguration.Builder(); configurationBuilder = configurationBuilder.withInitialDirectory(dir); @@ -137,6 +141,7 @@ public Optional showDialogAndGetSelectedDirectory() { return runInJavaFXThread(() -> Optional.ofNullable(directoryChooser.showDialog(null)).map(File::toPath)); } + /** * Shows an {@link JFileChooser#OPEN_DIALOG} and allows to select multiple files * @return List containing the paths of all files or an empty list if dialog is canceled