I am using the batch file example below that I got from batch file to monitor additions to download folder. I would like to modify this so that it loops through all the subf
Please.... make it powershell?
http://archive.msdn.microsoft.com/PowerShellPack contains the function Start-FileSystemWatcher
.
Please don't inflict this batch file on any system.
Powershell.com has samples
Here's a sample from this thread:
$folder = '<full path to the folder to watch>'
$filter = '*.*' # <-- set this according to your requirements
$destination = '<full path to the destination folder>'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $true # <-- set this according to your requirements
NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
}
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp"
Move-Item $path -Destination $destination -Force -Verbose # Force will overwrite files with same name
}
Eventually, unregister the subscription: Unregister-Event -SourceIdentifier FileCreated