Last active
October 14, 2015 07:46
-
-
Save dlidstrom/6cd076431848c9a96795 to your computer and use it in GitHub Desktop.
Runs a batch file continuously whenever another file is changed.
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
# 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