将新文件夹添加到某个位置时触发脚本 [英] Trigger script when new folder has been added to a location

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

问题描述

我正在自动化一个过程,并且已经为此制作了一个 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.

谢谢.

推荐答案

个人我会使用 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天全站免登陆