我正在自动化一个流程,并且已经为此制作了一个 powershell 脚本。现在我需要制作一些东西,每次将新文件夹添加到特定位置(即删除新版本)时都会调用该脚本。
我应该为此使用什么。 WCF 太多了吗?如果没有,有任何线索吗?任何有用的链接。
或者另一个 powershell 脚本更适合这个?
请记住,我还需要检查子文件夹。
Thanks.
我个人会使用 System.IO.FileSystemWatcher
$folder = 'c:\myfoldertowatch'
$filter = '*.*'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter
$fsw.IncludeSubdirectories = $true
$fsw.NotifyFilter = [IO.NotifyFilters]'DirectoryName' # just notify directory name events
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { ... do my stuff here } # and only when is created
使用它来停止观看事件
Unregister-Event -SourceIdentifier FileCreated
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)