Move file to other locations dynamically using callbacks

I’m trying to create a feature for a plugin which moves a file to a designated “archived” folder when it is labelled as “archived”. However, I’m wondering if there is a possible approach I can use to move the file location automatically using the plugin? For example, like follow:

if (editor.getContent().contains('archived')) {
        // move the current file to a specific file path like /All/Archived/

So far I’ve been working around this feature where each time, I extract the content of the file, delete the file from its original location, create a new file in the new location, then paste back the content. But I realized this approach doesn’t work as a bunch of commands are getting triggered whenever a new file is created. So is there a way where I can just move the original file to the new folder without having to create a new file? Thanks

I usually give the Obsidian Typescript file a search and see if anything likely comes up. This is the function you want.

1 Like

Thank u for the reply. How can I call this API in my main.ts file? For example, I’ve tried using

etc but it seems to be incorrect. Do I need to import additional packages? Thanks

If you look in the file I linked, you can see what class that function is in (line 1275). So you can either import that class, or use it from using the name it’s exported as (line 356).