Skip to content

Instantly share code, notes, and snippets.

@dlidstrom
Last active October 14, 2015 07:46
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 dlidstrom/6cd076431848c9a96795 to your computer and use it in GitHub Desktop.
Save dlidstrom/6cd076431848c9a96795 to your computer and use it in GitHub Desktop.
Runs a batch file continuously whenever another file is changed.
# watch a file changes in the current directory,
# execute all tests when a file is changed or renamed
param($BatFile)
if (($BatFile -eq $null) -or (-not (Test-Path -Path $Batfile)))
{
"Specify bat file to run continuously."
exit
}
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = Get-Location
$watcher.IncludeSubdirectories = $false
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName
& $BatFile
while ($true) {
$result = $watcher.WaitForChanged([System.IO.WatcherChangeTypes]::Changed -bor [System.IO.WatcherChangeTypes]::Renamed -bOr [System.IO.WatcherChangeTypes]::Created, 1000);
if( $result.TimedOut ) {
continue
}
"Change in $($result.Name)"
if ($result.Name -Match ".png") {
"Skipping"
continue
}
& $BatFile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment