I’d like to access my plugin’s directory in the plugin’s code. For background, I’m doing this because I want to make backup copies of data.json file whenever the plugin makes migrations to that file.
I know that my plugin resides in a directory .obsidian/plugins/obsidian-shellcommands that is relative to the vault’s directory.
I can divide finding out the plugin’s directory to the following parts:
Add /.obsidian/plugins to the path. This is problematic because .obsidian can be configured by a user to be something else. Where do I find it out?
Add the plugin’s folder name to the path. This can be retrieved with this.manifest.id when this refers to the plugin’s main class.
So the actual point of this topic is to find and answer to the step 2. Of course, if Obsidian API happens to have a method that does all of these three steps for me, I’d be glad to hear about it also.
Note: I’m not using this approach anymore, you might need to look into normalising the path (perhaps with normalizePath, starting with the config dir because that method only works for paths in the vault).
For the people still looking for the absolute path to the plugin this.app.vault.adapter.basePath did the trick for me. Though, I don’t think it’s super official, so proceed with caution.