Watch file for changes and run command with powershell

前端 未结 7 862
终归单人心
终归单人心 2020-11-28 07:01

Is there any simple way(i.e., script) to watch file in Powershell and run commands if file changes. I have been googling but can\'t find simple solution. Basically I run scr

7条回答
  •  醉话见心
    2020-11-28 07:51

    You can use the System.IO.FileSystemWatcher to monitor a file.

    $watcher = New-Object System.IO.FileSystemWatcher
    $watcher.Path = $searchPath
    $watcher.IncludeSubdirectories = $true
    $watcher.EnableRaisingEvents = $true
    

    See also this article

提交回复
热议问题