47

How do I search in a folder in sublime text 2 with file extension?

My where when I use:

*.js

searches globally for all js files.

If I try to restrict it to a folder:

/project/*.js

it matches nothing.

Frank Tan
  • 4,234
  • 2
  • 19
  • 29
Harry
  • 52,711
  • 71
  • 177
  • 261

3 Answers3

81

Instead of this:

/project/*.js

Try using this:

project .js

This should match files which have project in the path and have a .js extension

EDIT: The above assumes you're trying to find all the files with .js extension using the Goto Anything feature in Sublime Text.

In case you'd like to search within .js files located within a directory, you can add an Include Filter in the search path:

/project,*.js

This will search for the text you've entered, limiting the scope to files within /project and it's sub-directories having the extension .js.

Reference: Sublime Text Docs - Search Scope

EDIT 2: For Sublime Text 3, refer Simons answer below.

godfrzero
  • 2,230
  • 1
  • 26
  • 31
27

godfrzero's answer does not work in Sublime 3 as it actually includes ALL JS files plus ALL files in the project folder.

Instead, you need to specify it similar to how you had it originally...

project/*.js

Note that there's no leading slash, as that will treat it as an absolute path which you won't want in most cases. To include multiple file types within the folder, I think you need to specify it like this:

folder/*.ctp,folder/*.php

This will match any of the following files:

/app/folder/example.ctp
/app/folder/example.php
/app/folder/subfolder/example.ctp
/app/long/path/folder/subfolder/example.php

I know you asked about Sublime 2, but hopefully this helps others (like myself) who are Googling for such advice.

Simon.

Simon East
  • 55,742
  • 17
  • 139
  • 133
  • 3
    I wanted to do this with an absolute path and it didn't work. I removed the leading slash and it worked perfectly. Example: `/home/user/folder/*.rb` does not work `home/user/folder/*.rb` works – Redithion Feb 12 '16 at 15:45
  • 2
    Note that you've got to use forward slashes, even in Windows, though right-clicking and selecting "Find in Folder" in your sidebar gives you an absolute path with unescaped backslashes (again, in windows). A little unintuitive for me; ymmv. – ruffin Feb 03 '17 at 23:01
  • 2
    This doesn't work. `...\*.css: ERROR: Unable to open file` – mbomb007 Oct 24 '18 at 14:28
  • The accepted answer actually works in ST3. This too: https://stackoverflow.com/a/28818727/2415524 – mbomb007 Oct 24 '18 at 14:34
5

My Sublime ver: 3.2.2

Adding to above answers, I was trying to find in all python files starting with test_ . so this is how I did it.

After pressing Ctrl+Shift+F, in the window.

Where : /home/WorkDir/test, test_*.py

enter image description here

Arindam Roychowdhury
  • 5,927
  • 5
  • 55
  • 63