Search code examples
sublimetext3sublimetextsublime-text-plugin

Get selected folder from sidebar in Sublimetext


I'm looking for method to get the path from folder that exist in the sidebar. So far, I found this way:

class AddConfigCommand(sublime_plugin.WindowCommand):
    def run(self, files):
        if not files:
            files.append(sublime.active_window().active_view().file_name())

which return me the path only if it a file, but if it a folder it return me None. The files parameter came from Side Bar.sublime-menu file:

{
    "caption": "Create New Config",
    "command": "add_config",
    "args": {
      "files": []
    }
}

Another option that maybe can help in some way is to get the "where" line from the function 'Find in folder' which return the path of file/folder.


Solution

  • The "args" variable defines all the input sublime will send to your method. "files" is an array that contains all the chosen files on the sidebar, and files ONLY.

    To get the directories chosen you need to pass the "paths" variable on your sublime-menu file like so:

    {
    "caption": "Create New Config",
    "command": "add_config",
    "args": {
      "paths": []
    }