![]() Pattern is not a regular expression instead it follows rules similar to shellįor syntax. Use patterns to match filenames in current directory and subdirectories. Print the names of the files found before watching files and folders: FileWatcher.new(,true).watch do |filename| watch ( 0.5 ) do | filename | puts " Updated " + filename end To check for changes more often than the default once every second: FileWatcher. watch ( ) do | filename, event | if ( event = :changed ) puts " File updated: " + filename end if ( event = :delete ) puts " File deleted: " + filename end if ( event = :new ) puts " Added file: " + filename end end To detect if a file is updated, added or deleted: FileWatcher. ![]() watch do | filename | puts " Updated " + filename end Watch a list of files and directories: require ' filewatcher ' FileWatcher. list, -l: Print name of files being watched exclude, -x : Exclude file(s) matching (default: "") include, -n : Include files (default: *) recurse, -r : Recurse into the directory, watching everything matching 'expression' exec, -e: Execute file as a script when file is updated. Command line options -interval, -i : Interval in seconds to scan filesystem. The environment variables $FILEPATH, $FILEDIR and $FSEVENT is also available. Node whenever a javascript file is updated: $ filewatcher *.js 'node $FILENAME' On unix like systems the command has to be enclosed in single quotes. The environment variable $FILENAME is available in the shell command argument. Watch the "src" and "test" folders recursively, and run test when theįilesystem gets updated: $ filewatcher "src test" "ruby test/test_suite.rb" When a file is beeing updated by using the -list/-l option: $ filewatcher -l *.css 'echo file: $FILENAME' Print a list of all files matching *.css first and then output the filename Python, ruby, perl, php, javascript or awk script. Works with files with file extensions that looks like a Try to run the updated file as a script when it is updated by using the In Linux/OSX: > filewatcher '*.js' 'node $FILENAME' This will make filewatcher look for files in Place filenames or filenames in quotes to use ruby filename globbing instead In Linux/OSX: $ filewatcher *.js 'node $FILENAME' Powershell: > filewatcher *.js "node %FILENAME%" Run any javascript in the current directory when it is updated in Windows Run the echo command when the file myfile is changed: $ filewatcher "myfile" "echo 'myfile has changed'" Shell command: shell command to execute when a file is changed Needs Ruby and Rubygems: $ gem install filewatcherįilewatcher scans the filesystem and execute shell commands when files are ![]() Monitors changes in the filesystem by polling. No dependencies or platform specific code. Lightweight filewatcher weighing less than 200 LoC.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |