Folder rename issue: "Folder with same name already exists!"
Hi,
Great job with this plugin, it is really useful!
However I am getting a "Folder with same name already exists!" when I try to rename a folder that has a folder note.
It is currently the only plugin enabled.
Following are the main settings:
Obsidian v1.7.7 Folder Notes v1.7.32
Oh, I realize that I don't have the issue if I change the following setting to anything but {{folder_name}}
But I would greatly prefer to not have to change this.
I found a work-around. What does not work is doing a rename using context menu (right-click on the folder). However, if I open the note of the folder and renames it (having the Sync folder name setting enabled), it rename the note and the folder without issue.
Same issue, sometimes right-click on the folder in navigation pane shows the error but somewhat manages to rename folder and sync attached files URI, sometimes not.
Unfortunately the trick to open parent folder in system explorer to rename it will desync attachment files URI and you'll have to fix them yourself.
It frequently happens when exporting from Zim to Markdown, as it renames all folders with underscores but not the files... In fact, I use Folder notes plugin to keep the same workflow as Zim. Once everything is renamed properly though, sync seems to work fine.
I'm experiencing the same issue. It likely occurs when using the following combination of settings:
Storage location:In the parent folderSync folder name:true
And it occurs when renaming folders using right-click.
Disabling Sync folder name is quite inconvenient. Regarding Storage location, I prefer keeping files in the parent folder as it creates more natural links.
It seems that handleFileRename is also being triggered at the last line of handleFolderRename.
https://github.com/LostPaul/obsidian-folder-notes/blob/main/src/events/handleRename.ts#L129
plugin.app.fileManager.renameFile(folderNote, newPath);
I’m not familiar with developing Obsidian plugins, so I don’t know the best way to fix this.
The following is a rather messy workaround, but modifying Vault/.obsidian/plugins/folder-notes/main.js as shown below seems to prevent the error.
Changing lines 5218 to 5269: Vault/.obsidian/plugins/folder-notes/main.js
let isFolderRenaming = false; // [!] Add this line.
function handleFolderRename(file, oldPath, plugin) {
const fileName = plugin.settings.folderNoteName.replace("{{folder_name}}", file.name);
const folder = plugin.app.vault.getAbstractFileByPath(file.path);
const folderNote = getFolderNote(plugin, oldPath);
if (!(folderNote instanceof import_obsidian28.TFile))
return;
if (!(folder instanceof import_obsidian28.TFolder))
return;
const excludedFolders = plugin.settings.excludeFolders.filter((excludedFolder2) => excludedFolder2.path.includes(oldPath));
excludedFolders.forEach((excludedFolder2) => {
if (excludedFolder2.path === oldPath) {
excludedFolder2.path = folder.path;
return;
}
const folders = excludedFolder2.path.split("/");
if (folders.length < 1) {
folders.push(excludedFolder2.path);
}
folders[folders.indexOf(folder.name)] = folder.name;
excludedFolder2.path = folders.join("/");
});
plugin.saveSettings();
const excludedFolder = getExcludedFolder(plugin, file.path);
if ((excludedFolder == null ? void 0 : excludedFolder.disableSync) && !folderNote) {
return removeCSSClassFromEL(file.path, "has-folder-note");
}
let newPath = "";
if (plugin.settings.storageLocation === "parentFolder") {
const parentFolderPath = getFolderPathFromString(file.path);
const oldParentFolderPath = getFolderPathFromString(oldPath);
if (parentFolderPath !== oldParentFolderPath) {
if (!plugin.settings.syncMove) {
return;
}
newPath = `${parentFolderPath}/${fileName}.${folderNote.extension}`;
} else if (parentFolderPath.trim() === "") {
folderNote.path = `${folderNote.name}`;
newPath = `${fileName}.${folderNote.extension}`;
} else {
folderNote.path = `${parentFolderPath}/${folderNote.name}`;
newPath = `${parentFolderPath}/${fileName}.${folderNote.extension}`;
}
} else {
folderNote.path = `${file.path}/${folderNote.name}`;
newPath = `${file.path}/${fileName}.${folderNote.extension}`;
}
isFolderRenaming = true; // [!] Add this line.
plugin.app.fileManager.renameFile(folderNote, newPath);
setTimeout(() => isFolderRenaming = false, 500); // [!] Add this line.
}
function handleFileRename(file, oldPath, plugin) {
if (isFolderRenaming) return; // [!] Add this line
~~If you set Storage location to Storage location: Inside the folder, applying the changes mentioned above will cause a new bug to appear.~~
It might have just been my imagination.
Does this error still occur with the latest plugin version?
Currently on v1.7.35 and I have renamed many folders this way and didn't have the issue again. I also see that v1.8.16 is out so I'll try it later.