Ensure unique filename in a vault

hope to ensure unique filename in different folder in a vault.

it means just use filename (not filepath) as NOTE ID

2 Likes

Is it possible now?

Please add this feature. I have many folders but my system calls for unique file names. This is an important feature for me and necessary for my workflow.

A few versions ago it was normal behavior, or am I wrong?

1 Like

Why is it important?

  • It’s important for PKM to use unique clear names in the total vault.
  • I use an Inbox-folder for “wip” notes and move them to a final folder when I finished the note (now I got name conflicts)
  • Zettelkasten-like names are hard to reference, because those names make no sense.
  • eg. “2022.10.22.10394” vs “Writing is thinking”

Zettelkasten is great to crate ideas, its even better when your files have clear, unique names which you can create by yourself - for the total vault.

1 Like

@PitchPowerBank here’s a one-liner that will find any duplicate note names:

const duplicates = app.vault.getFiles().filter((x, _, a) => x.name.match(/\.md$/) && a.filter(y => y.name === x.name).length > 1).map(x => x.path)

You could use Dataview to display the list of files for you:

```dataviewjs
const duplicates = app.vault.getFiles()
  .filter((x, _, a) => x.name.match(/\.md$/) && a.filter(y => y.name === x.name).length > 1)
  .map(x => x.path)

dv.list(duplicates)
```

If you wanted you could put it into a Templater or other script so you can launch it from a hotkey.

1 Like

Based on a discussion in the discord somebody suggested a great work around. Never create new files with CMD-N use instead CMD-O, it will create a new file if the name is in use. I will change the short cut for CMD-N to CMD-O as well.

1 Like

Thank you. Fortunately I do not have any duplicates. I run into this issue the first time today. I posted a solution which works for me.

Thanks for the dataview code.

for the note with the same name, do they have the same last modification time or creating time? can this information be also shown or used to sort the result?

Are there any updates on this recently?

Here is the improved version of the script:

  • Includes case-insensitive search
  • Ignores spaces during search
const duplicates = app.vault.getFiles().filter(
	(x, _, a) => 
		x.name.replace(/\s/g, '').toLowerCase().endsWith('.md') && 
		a.filter(
			(y) => y.name.replace(/\s/g, '').toLowerCase() === x.name.replace(/\s/g, '').toLowerCase()
		).length > 1
	)
	.map((x) => "[["+x.path+"]]");
dv.list(duplicates)