当新的文件夹已经被添加到一个位置触发器脚本 [英] Trigger script when new folder has been added to a location

查看:136
本文介绍了当新的文件夹已经被添加到一个位置触发器脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我自动化的过程,并已取得PowerShell脚本为。现在,我需要的东西,这将调用脚本每次一个新的文件夹已被添加到一个新的构建被丢弃的特定位置,即。
我应该使用什么这一点。 WCF是太多了?如果没有,得到了任何线索?任何有用的链接。
或者是另一个PowerShell脚本更好?

I'm automating a process and already made a powershell script for that. Now I need to make something which will call that script everytime a new folder has been added to a specific location i.e. a new build is dropped. What should I use for this. Is WCF too much? And if not, got any leads for that? Any useful links. Or is another powershell script better for that?

请记住我需要检查的子文件夹了。

Keep in mind I need to check subfolders too.

感谢。

推荐答案

Personnaly I'ld使用System.IO.FileSystemWatcher

Personnaly I'ld use 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

这篇关于当新的文件夹已经被添加到一个位置触发器脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆