From 6d0061ad49434f26f3f8e31f7debef93ee2f7157 Mon Sep 17 00:00:00 2001 From: Mike Farr Date: Fri, 4 Apr 2025 09:05:39 -0600 Subject: [PATCH] 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 --- main.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/main.ts b/main.ts index cd8bf6d..9d537b5 100644 --- a/main.ts +++ b/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; }