Sublime Forum

Watching folder in sublimetext

#1

When a file is created or deleted outside of SublimeText these changes are still noticed by ST and the list of files is updated accordingly in the sidebar.

Is is possible to trigger a custom command when the list of source files / folders from *.sublime-project "folders":[] changes?

0 Likes

#2

Generally speaking, no; the list of files that are available in the side bar isn’t available via the API. To gather it you would need to manually query the contents of the folders in the side bar (and apply any include/exclude patterns present in the project) to crawl them yourself.

If you just want to know when the list of folders is modified (i.e. someone added or removed one from the project), that’s possible in recent builds. That could be your trigger to do a re-scan of said folders so you can detect if the list of files is different.

In build 4050, the on_load_project event was added, which triggers whenever a project is loaded. That includes when one is initially populated into a window as well as when the project file is modified.

This doesn’t apply to windows with anonymous project data however; only windows that have a sublime-project associated with them.

import sublime
import sublime_plugin


class TestListener(sublime_plugin.EventListener):
    def on_load_project(self, window):
        print('Project loaded in %s' % str(window))
        print(window.folders())
3 Likes