Skip to content

Commit 169af5c

Browse files
committed
Simplify the code to get the new path
Signed-off-by: kaiquekk <[email protected]>
1 parent 4cf8d8d commit 169af5c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/main/java/org/jabref/gui/fieldeditors/LinkedFileViewModel.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,11 @@ public void edit() {
359359
public void renameFile() {
360360
LinkedFileRenameDialogView dialog = new LinkedFileRenameDialogView(this.linkedFile);
361361
String oldFile = this.linkedFile.getLink();
362-
int nameCount = Paths.get(oldFile).getNameCount();
363-
Path subPath = Paths.get(oldFile).subpath(0, nameCount - 1);
364362
Optional<LinkedFile> editedFile = dialog.showAndWait();
365363
editedFile.ifPresent(file -> {
366-
String newFile = System.getProperty("file.separator") + subPath.toString() + System.getProperty("file.separator") + file.getLink();
367-
this.linkedFile.setLink(newFile);
368-
FileUtil.renameFile(Paths.get(oldFile), Paths.get(newFile));
364+
Path newFile = Paths.get(oldFile).resolveSibling(file.getLink());
365+
this.linkedFile.setLink(newFile.toString());
366+
FileUtil.renameFile(Paths.get(oldFile), newFile);
369367
});
370368
}
371369

0 commit comments

Comments
 (0)