Sublime Forum

Programmatically find a file in project

#1

I have a (really) big project. I want to be able to find a file, open it and go to a specific line given the file name specified as “Foo.txt:24”, where “Foo.txt” is the name and “24” is the line.

Basically, the same thing that you can do when pressing Cmd+P.

How can I do that from a plugin? I tried looking at the window API to obtain all open directories and then use os.walk to traverse it. But my project is really big and Sublime’s Cmd+P does it so much faster than os.

0 Likes

#2

That’s more or less the only way to do it; the contents of the Side Bar and the contents of the file catalog it contains aren’t available to the API.

Sublime scans the list of folders once and then applies file watches on them to know when things are changing. You’d have to more or less replicate the same thing to get the same effect.

0 Likes