Sublime Forum

How to get project path?

#1

It seems to have be asked several times, but I couldn’t find any answer to this question: how can I get the path of the current project? (from a plugin)

TIA

0 Likes

#2

window.folders() gives you a list of folders that are in the project. Perhaps that will give you what you want.

0 Likes

#3

Thanks for your answer.

I found window.folders(), but it’s not what I want. This is an arbitrary list of folders, I’m looking for the project file itself.

0 Likes

#4

Take a look at facelessuser’s FavoriteFiles plugin. There is some functionality that needs to know where the project file is, but I believe when he did it, it was pretty much a kludge. I haven’t looked at the code in a long time, so he may have found a more elegant way to do it.

0 Likes

#5

No, it is still a kludge, but yes I have do have a way to get the project path. In general, it is pretty straight forward, but the file you have to parse isn’t always up to date…meaning you can’t get the project path unless you force this particular file to update. That is were it gets ugly.

0 Likes

#6

I see… do you think it’s better to have the user explicitly set the path in some config file?

0 Likes

#7

[quote=“greg”]
I see… do you think it’s better to have the user explicitly set the path in some config file?[/quote]

Depends on what you want to do. It is certainly the easiest thing to do. Hopefully one day Jon will expose this in the API. I am sure it is always up to date in some memory buffer, but that only gets flushed out to the file on very specific events.

0 Likes

#8

I’ve done a plugin to sync the source folder of my web projects with the web root folder.

So I’ll use pathes explicit set in config files until the API is exposed.

Thanks for your help!

0 Likes