Skip to content

Instantly share code, notes, and snippets.

@Tattoo
Last active June 20, 2017 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tattoo/5e6e6e608c42ba819dbadae92201950e to your computer and use it in GitHub Desktop.
Save Tattoo/5e6e6e608c42ba819dbadae92201950e to your computer and use it in GitHub Desktop.
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