I have created a IO.filesystemwatcher
to monitor a folder and take an action when certain file types are written to the location. I am looking for file types .jpg
and .tmp
. I have named the filter as a variable, and the filter works when including one file type, but not two types.
Code below functions correctly:
$filter = '*.jpg'
New-Object IO.FileSystemWatcher $Folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Code below functions correctly:
$filter = '*.tmp'
New-Object IO.FileSystemWatcher $Folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
Code below DOES NOT function:
$filter = '*.tmp','*jpg'
New-Object IO.FileSystemWatcher $Folder, $filter -Property @{IncludeSubdirectories = $true;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
I have also tried $filter = '*.tmp' -or '*jpg'
I am sure there's a different way to do this to make it work, but I am not very good at working with IO.filesystemwatcher
. Any recommendations are appreciated.
Thanks