0

Recently I have connected my FTP to Sharefile. Sharfile creates a .syncdb file in my ftp folders. I have code that checks my FTP folder for new files created, copies them to a new folder and sends notification emails that files have arrived. Sometimes I am now receiving emails for .syncdb-wal and syncdb-shm files. This actually doesn't create the file to be copied, but it does create a notification email and creates a blank folder which is a nuisance. I am trying to just not include these files with a filter but it doesn't seem to be working. I am not sure if you can declare more than one extension for the filter. Here is the code below that I am trying to use to filter files to not include files with the extensions .syncdb-wal and syncdb-shm, I am probably missing something easy.

$MonitorFolder = Get-Content "C:\Users\RickG\Desktop\ScanFTPDeptClients\Pathlist.txt"

$filter ='*.syncdb-wal, *.syncdb-shm '
foreach ($path in $MonitorFolder){
$watcher = New-Object System.IO.FileSystemWatcher $path, -ne $filter
#Files only. Default is files + directory
$watcher.NotifyFilter = [System.IO.NotifyFilters]'FileName,LastWrite'
}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
SikRikDaRula
  • 133
  • 1
  • 14
  • 1
    That is not a valid filter. Filters are for the File System Provider, which only allows for a single string inclusive filter. Meaning you can only tell it what to include in the results, not what to exclude, and you can only set one filter, not several. So `*.txt` is fine to include only .txt files, but you cannot do `*.txt, *.docx`. – TheMadTechnician Jul 19 '16 at 20:13

1 Answers1

2

No you can't apply multiple file name filters.

Inspect the name of the file in the event handler instead

$watcher = New-Object System.IO.FileSystemWatcher $path
$watcher.NotifyFilter = [System.IO.NotifyFilters]'FileName,LastWrite'
$watcher.Filter = '*.*'

Register-ObjectEvent $watcher -EventName Created -Action {
    if ($EventArgs.Name -eq '.syncdb-wal' -or $EventArgs.Name -eq '.syncdb-shm'){
        # nope, not interested
        return
    }
}
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • Thanks! Your a life saver, One more question if you don't mind....How can I check if a file is still being written to before copying, sometimes my files don't copy and show up in email as` [filename].pdf.filepart`, its mainly pdf's that are over like 60kbs – SikRikDaRula Jul 19 '16 at 23:47
  • 1
    Listen for the `Changed` event instead, and make sure the extension is not `.filepart` (also inside the Action) – Mathias R. Jessen Jul 19 '16 at 23:49