Last active
June 20, 2017 14:54
-
-
Save Tattoo/5e6e6e608c42ba819dbadae92201950e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param([string]$folder) | |
$command="$args" | |
$filter = "*.*" | |
$Watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{ | |
IncludeSubdirectories = $true | |
EnableRaisingEvents = $true | |
} | |
Register-ObjectEvent $Watcher Changed -SourceIdentifier Watcher -Action { | |
$command=$event.MessageData | |
Write-Host "Running command: $command" -fore green | |
$out = Invoke-Expression "$command 2>&1" | |
Write-Host "$out" | |
} -MessageData $command | |
# Checks for changes in file/folder, executes command when so happens. | |
# Invoke like this from powershell: PS > .\filewatcher echo hello -folder absolute\path\to | |
# You need to restart the powershell session to clear the filewatcher | |
# USE ABSOLUTE PATHS TO FILES AND FOLDERS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment