Skip to content

Instantly share code, notes, and snippets.

@dan-hills
dan-hills / Wait-File.ps1
Created October 25, 2025 12:33 — forked from steviecoaster/Wait-File.ps1
Implement a FileSystemWatcher in PowerShell
function Wait-File {
<#
.SYNOPSIS
Monitors a file system path for changes and executes a script block in response to specified events.
.DESCRIPTION
The Wait-File function creates a FileSystemWatcher to monitor a specified directory for file system changes.
It registers event handlers for specified events (Created, Changed, Deleted, Renamed) and executes a
custom action when those events occur. The function runs continuously until manually stopped (Ctrl+C).