mirror of
https://github.com/mfarr/obsidian-archive.git
synced 2026-07-22 05:41:33 +00:00
Normalize destination file path (#10)
Fixes path issue when attempting to archive an item from the root of the vault by normalizing the destination file path. Resolves #9
This commit is contained in:
parent
d16c56bd1a
commit
6d0061ad49
1 changed files with 8 additions and 6 deletions
14
main.ts
14
main.ts
|
|
@ -86,10 +86,13 @@ export default class SimpleArchiver extends Plugin {
|
|||
return false;
|
||||
}
|
||||
|
||||
const existingItem = this.app.vault.getAbstractFileByPath(
|
||||
const destinationFilePath = normalizePath(
|
||||
`${this.settings.archiveFolder}/${file.path}`
|
||||
);
|
||||
|
||||
const existingItem =
|
||||
this.app.vault.getAbstractFileByPath(destinationFilePath);
|
||||
|
||||
if (existingItem != null) {
|
||||
new Notice(
|
||||
`Unable to archive ${file.name}, item already exists in archive`
|
||||
|
|
@ -98,7 +101,9 @@ export default class SimpleArchiver extends Plugin {
|
|||
return false;
|
||||
}
|
||||
|
||||
const destinationPath = `${this.settings.archiveFolder}/${file.parent?.path}`;
|
||||
const destinationPath = normalizePath(
|
||||
`${this.settings.archiveFolder}/${file.parent?.path}`
|
||||
);
|
||||
|
||||
const destinationFolder =
|
||||
this.app.vault.getFolderByPath(destinationPath);
|
||||
|
|
@ -107,10 +112,7 @@ export default class SimpleArchiver extends Plugin {
|
|||
await this.app.vault.createFolder(destinationPath);
|
||||
}
|
||||
|
||||
await this.app.fileManager.renameFile(
|
||||
file,
|
||||
`${this.settings.archiveFolder}/${file.path}`
|
||||
);
|
||||
await this.app.fileManager.renameFile(file, destinationFilePath);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue