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:
Mike Farr 2025-04-04 09:05:39 -06:00 committed by GitHub
parent d16c56bd1a
commit 6d0061ad49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

14
main.ts
View file

@ -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;
}