Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

2 Commits

Repository files navigation

Watch directory and execute

for each new file in the watched directory, execute given command

how to?

  • Download and install python 3
  • Execute: pip3 install watchdog
  • Execute: python3 main.py --help

expected result

r-santos@rafmbp~/d/p/watchnexecute-python>python3main.py--helpusage: main.py [-h] dircmdWatchdirectoryandexecutecmd.
positionalarguments:
dirdirectorytowatchcmdcmdtobeexecutuedforeachnewfileoptionalarguments:
-h, --helpshowthishelpmessageandexit

Usage example #1

start: python3 main.py ./ "cat %s | grep thingy"
output: watching directory: "./"
will execute "cat %s | grep thingy"for directory modified files.
input: touch example.test
output: executing "cat ./example.test | grep thingy"
input:
echo"thingy">> example.test output: executing "cat ./example.test | grep thingy"
thingy

Usage example #2

open new file in text editor MacOS

r-santos@rafmbp ~/d/p/watchnexecute-python> python3 main.py ./ "open -a Visual\ Studio\ Code %s"
watching directory "./"
will execute "open -a open -a Visual\ Studio\ Code %s"for directory modified files.

Visual studio code should pop up with the modified or created file.

If the file is deleted the cmd will throw an error, telling visual studio couldn't find the file.

About

Watch a directory and execute given system cli command. Python3 with watchdog

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages