I\'d like to monitor a Windows 7 folder and have a .bat file run when any new files are added to the folder. It seems like I should be able to do this using powershell, whic
you can also use this code to run ps1 file in background instead of invoke-item
Invoke-Expression -Command "C:....\somescript.ps1"
Here you go:
$folder = 'f:\test' # Enter the root path you want to monitor.
$filter = '*.html' # You can enter a wildcard filter here.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green
write-host "test"
Invoke-Item 'f:\test\test.bat'
}