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:
- Get vault’s absolute directory, which is discussed here: How to get vault absolute path? .
/.obsidian/pluginsto the path. This is problematic because
.obsidiancan 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
thisrefers 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.
Thank you for your support!