Rename imported files if they contain invalid characters

Steps to reproduce

Create a file named “file#1.txt”
Create a new blank note in Obsidian 1.1.9.
Drag and drop the file into the blank note to embed it by drag-and-drop.

Expected result

File is imported to attachments folder and a working embedded file block for the file is created in the note.

Actual result

File is successfully imported to attachments folders, however the embedded file block for the file reports the file missing: “attachments/file#1.txt” is not created yet. Click to create.


  • Operating system: Linux
  • Debug info:

Additional information

I see the issue with invalid characters in files created outside Obsidian is well known. I’m creating this report because it’s still a problem.

I frequently embed files this way during my workflow and it requires me to rename embedded files and edit the embed text by hand which is cumbersome. (I have to search in folder to find the file because I can’t use the quick switcher as that only opens MD files. Sometimes I can find the file in the left-hand explorer pane, but some of my vaults have over a hundred attachments and this takes too long.)

Renaming files by stripping or replacing invalid characters during insertion would be an acceptable solution for me, but I can imagine use cases where that may introduce problems of its own.

1 Like

What happens if, after the steps you reproduce, you create a file “attachments/file” containing a heading “1.txt”?

I’m not sure what would happen but it wouldn’t do anything to resolve this issue. Why are you suggesting this?

The # is used in links to target headings, which is why it’s forbidden in note names. I asked partly to point that out, and partly because I wasn’t sure if it would still work properly under the circumstances.

I know # (and ^) have special functions in links, I’ve used them both, and other characters are forbidden in note names for other reasons. I mentioned that in my first post. I understand your curiosity but it’s unrelated to my problem and off-topic and I find that frustrating.

It wasn’t clear to me from your post that you knew why the characters are forbidden. When I said I was unsure about the result, I wasn’t asking out of curiosity, I just wasn’t sure enough to state it outright and wasn’t willing to test it out. I’m sorry I frustrated you — my post should have been more straightforward.

Maybe I didn’t make it clear enough that I understand why this happens. I know less tech-literate people would get confused by this and Obsidian’s other markup quirks.
When I came here to report the bug I saw other threads about the problem with characters in file names created outside Obsidian, so as I wrote I know it’s a known issue. I thought that would imply that I understand why these characters are a problem.

With Automator in macOS, users can create folder actions where, in this example, any file dragged into the folder is automatically renamed by having an automation assigned to it that searches file names for hashtags and replaces them with underscores or hyphens etc.

Does Linux have anything like that which you could configure? Much easier than renaming by hand.

Hashtags do work with files stored outside of the vault, so if the developers implement a name-changing system, it would need to apply only to files actually imported to Obsidian, yes?

EDIT: If you want to keep the hashtag in the file name, you can copy the file to the attachments folder and then create a file-path link to it:


1 Like

This wasn’t a help request, I can deal with manually renaming for now, I’m not looking for any automated crutches. I just wanted to submit a bug report so it’ll get fixed in the future.

I really hope it doesn’t. There’s no real bug here. Just user error: use it as it was designed to be used.

I think it’s a UI bug — Obsidian should at least tell the user like it does when renaming files.

1 Like

Breath of fresh air. You’re probably a better judge of these things than I am.

![[attachments/file#1.txt]] is a link to a heading called 1.txt in note called file, so there’s nothing wrong with the syntax, is there? It is valid.

And when we drop a text file called file#1.txt into a note, we get the warning that "attachments/file#1.txt" is not created yet. Click to create. and know immediately that the import has a problem. In this case, a user-generated problem for employing syntax that is trying to create a link to a heading in a note. If the user wants to keep making the same error, well … good to have a choice. :grin:

I think the UI is clear, but the developers might think it’s worth changing. More important things to focus on, I imagine, especially when it already works if the user complies.

I’d rather Obsidian didn’t change the file name automatically. Don’t want Obsidian nannying me or my files.

As this isn’t something that’s been designed for or implemented by the devs, it is a feature request — I’ve moved it to that category.

1 Like