Sublime Forum

Open all file with filename = pattern


i need to open any file whose filename matches a pattern within a directory.

An example usage of “show_overlay” is shown below:

{ "keys": ["ctrl+p"], "command": "show_overlay", "args": {"overlay": "goto", "show_files": true} },

However, i don’t need the user input for fuzzy search. Instead, i would like to open any file whose filename matches a certain pattern (i think regex would be better than fuzzy in this case).

I wasn’t able to find sources for GotoAnything. Does ST API provide any method to search for filenames within a folder, instead of file content search?



There’s no API for knowing what files are considered to be part of a project (or anonymous projects, such as windows with folders open but no sublime-project file persisting that information). Additionally, quick panels only support fuzzy matching and there’s no hook to alter that either.

The list of folders that are open in any given window is available via the window.folders() API endpoint. You can also use something like [v for v in window.views() if v.file_name() is not None] to find all view instances in the current window that relate to open files that have names on disk.

With that and the standard directory search functionality of Python, you can find any files whose names match whatever you like, and then open them or present them to the user for further filtering, etc.

Note that in this case the onus is on you to respect the list of included files or excluded folders and files in the added folders, if you want to replicate opening only from the list of files that are visible in the side bar.

1 Like