Sublime Forum

[Explained] Sublime Project: file/folder exclude patterns

#1

Hi,

How to hide only direct children of folder with "file_exclude_patterns": [ ... ]?
I have structure like this and I want to exclude Main Folder/*.js :confused:

  • Main Folder
    • Inner Folder
      • keep_me_pls.js
      • oh_and_me_too.js
  • hi_there.js
  • kiss_me.js
  • do_not_exclude_me_pls.jsxyz
  • good_bye.js

Thanks

3 Likes

#2

For reference, the patterns for including and excluding files and folders are in “glob” format.

This means that * matches any number of characters, including zero, and ? matches exactly one character. The glob spec states that * should never match / or \, but unfortunately Sublime Text doesn’t follow the spec in this regard. In Sublime Text, a * will match folder_name/subfolder/file.ext. Normally, one would expect to have to type */*/* for it to match. It is therefore impossible in ST to reference a base folder without it’s subfolders. :frowning:

You can however, match subfolders without matching the base folder, like this:

"file_exclude_patterns": ["scripts/?*/*.js"]

In this example, JavaScript files in the scripts folder would still appear, but not in any subfolders (or nested subfolders) of scripts.


To answer your question, then:

As a result of this limitation, you may have to use file_include_patterns instead like this:

"file_include_patterns": ["*.js?*", "Inner Folder/*"],

the *.js?* says include all files that end in .js and have at least one more character following that.

unfortunately, I can’t see any way to avoid needing to reference all your inner folders explicitly :frowning:

Of course, if you also have non JavaScript files, then this probably won’t help much, as it will only include what matches this pattern. It seems that one can’t combine file_include_patterns and file_exclude_patterns, nor is it possible to reference the same folder twice, to give different patterns that way.

6 Likes

#3

Thanks for such detailed great answer :+1: It helped me somehow

0 Likes