I need to see when a file is written to a directory. This directory is on a mapped network drive on a Windows 2003 server. If I copy files to this directory on the server, it works. If I write files remotely, it does not work. What can I do to make it work when files are written remotely? I would like to keep this as an event notification, but will change to a polling method if needed. If thats the correct way to do it, I need some best practice advice. Any detail I can get on how Windows' file write notifications work is welcome.
Example code:
$watchFolder = "Z:\watched";
$filter = "*.data";
$watcher = New-Object System.IO.FileSystemWatcher $watchFolder, $filter
$watcher.EnableRaisingEvents = $true
$created = Register-ObjectEvent $watcher Created -Action {
write-host "Found: $($eventArgs.FullPath)"
}
My experience level: salty unix admin, new to Windows development.
It would appear from the c# sample here http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx that you need full trust on the code and to set a NotifyFilter = [System.IONotifyFilters]::DirectoryName