1

Is there a way to restrict File Watcher to only trigger when the current file is under a certain directory?

Right now I can restrict the scope to Current file OR a matching Pattern like

file[project]:somefolder//*

The matching pattern scope looks for all modified files and I don't want to do that.

I only want it to trigger for the file I'm currently modifying in under a certain directory. Is there a way to do this?

supersan
  • 5,671
  • 3
  • 45
  • 64
  • Yes -- via custom scope -- include file name in pattern as well. – LazyOne Nov 20 '15 at 11:20
  • thanks for the reply.. can you please give me an example of this pattern.. I see the pattern for recursively selecting all files under a folder is `file[project]:somefolder//*`.. How do i specify that this pattern match the **currently open file** only? – supersan Nov 20 '15 at 11:45
  • There is no pattern for **currently open file**. **Custom** (user defined) scopes working with files in your project regardless of currently open/closed status -- they work with file/folder names. So my original comment should be read with "specific file in specific folder" in mind. The pattern (in general) would be `file[project]:somefolder/some-file.ext` -- that's what I've originally meant to say. – LazyOne Nov 20 '15 at 11:55
  • Better describe what the actual problem you are having that you need such setup -- maybe there are other approaches to handle your situation/setup. – LazyOne Nov 20 '15 at 11:56
  • Sorry, I think I may have understood File watchers all wrong. Ok, let me try to put it this way. How can I make it that **File watchers only triggers for the files I save with PhpStorm?** Because right now it tries to iterate over a lot of files it thinks have been modified, including files I never opened or edited once in phpstorm. I only want to trigger for files I save only – supersan Nov 20 '15 at 11:59
  • A week ago the uglify file watcher iterated over hundreds of javascript files in the bower_components directories (files I never once touched) and created .min.min.js of already minified files. So I want to keep the trigger to only the files I open and save by hand. – supersan Nov 20 '15 at 12:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/95694/discussion-between-supersan-and-lazyone). – supersan Nov 20 '15 at 12:03

1 Answers1

2

You need to create a custom scope with only your own files included (exclude bower_components and other stuff you don't like being watched) and set this scope to your file watcher. When being invoked for the first time, it will process all files in specified scope with extension matching chosen file type; once this process completes, it will listen to changes you make in files and process files in scope that are affected by the change

lena
  • 90,154
  • 11
  • 145
  • 150
  • Thanks for the help. The reason why I'd like it to monitor only the files opened in the IDE is because a week ago the uglify file watcher iterated over hundreds of javascript files in the bower_components directories (files I never once touched) and created .min.min.js of already minified files. I didn't exclude the bower_components folder because I have some of my own code it too. So right now I've created a custom scope including only the directories in bower_components which are mine. Lazyone has given me many ideas including exploring `gulp` / `grunt` which I'm currently looking into. – supersan Nov 20 '15 at 14:00