macoswatchfswatch

fswatch to watch only a certain file extension


I am using fswatch and only want it triggered if a file with extension .xxx is modified/created etc. The documentation and the second reference below indicate that:

Question: What is the regular expression to use to exclude all files that do not match the .xxx extension?

References:

Platform:


Solution

  • I'm fswatch author. It may not be very intuitive, but fswatch includes everything unless an exclusion filter says otherwise. Coming to your problem: you want to include all files with a given extension. Rephrasing in term of exclusion and inclusion filters:

    That is:

    The final command is:

    $ fswatch [options] -e ".*" -i "\\.ext$"
    

    If you want case insensitive filters (e.g. to match eXt, Ext, etc.), just add the -I option.