An API function to get the full system file path for note / file without extra phrases or text encoding

Use case or problem

Write now the only way to get the system file path for a file / note is with app.vault.getResourcePath() and then process it. I use this JS to do so (created with the help of GPT 4):

let filePath = app.vault.getResourcePath(app.workspace.getActiveFile());
filePath = decodeURIComponent(resourceUrl.replace(/app:\/\/[^\/]+\//, '/').split('?')[0]);

Proposed solution

There should be a function like app.vault.getFilePath() to do the same thing but more concise.

getActiveFile() return a TFile, where you can get the full path with .path: TFile - Developer Documentation (and TAbstractFile - Developer Documentation)

1 Like

I just tried let filePath = app.workspace.getActiveFile().path; in the console and it appears to only shows the path in the vault, not the whole OS file path. Does it work for you?

Oh sorry, I didn’t understand you want the OS path!

There is already the vault.adapter.getFullPath() method on desktop. (Don’t forget the instanceof check)

2 Likes

Thanks I got it working now!

let filePath = app.vault.adapter.getFullPath(app.workspace.getActiveFile().name)

A small correction: namepath

let filePath = app.vault.adapter.getFullPath(app.workspace.getActiveFile().path)
1 Like

Thanks!