将新文件夹添加到位置时的触发器脚本

kal*_*zel 3 powershell automation

我正在自动化一个进程,并且已经为此创建了一个PowerShell脚本.现在我需要制作一些东西,每次将新文件夹添加到特定位置时都会调用该脚本,即删除新构建.我该怎么用呢 WCF太多了吗?如果没有,为此获得任何线索?任何有用的链接.或者是另一个更好的PowerShell脚本?

请记住,我也需要检查子文件夹.

谢谢.

CB.*_*CB. 5

Personnaly我使用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
Run Code Online (Sandbox Code Playgroud)

用它来停止观看比赛

Unregister-Event -SourceIdentifier FileCreated
Run Code Online (Sandbox Code Playgroud)