3

私はプロセスを自動化しており、そのためのPowerShellスクリプトをすでに作成しています。ここで、新しいフォルダーが特定の場所に追加されるたびに、つまり新しいビルドが削除されるたびに、そのスクリプトを呼び出すものを作成する必要があります。これには何を使うべきですか。WCFが多すぎませんか?そうでない場合は、そのためのリードがありますか?便利なリンク。または、別のPowerShellスクリプトの方が適していますか?

サブフォルダもチェックする必要があることを覚えておいてください。

ありがとう。

4

2 に答える 2

5

個人的には 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
于 2012-05-10T08:03:58.243 に答える
0

これを試して:

$fsw = New-Object System.IO.FileSystemWatcher -Property @{
    Path = "d:\temp"
    IncludeSubdirectories = $true #monitor subdirectories within the specified path
}

$event = Register-ObjectEvent -InputObject $fsw –EventName Created -SourceIdentifier fsw -Action {

    #test if the created object is a directory
    if(Test-Path -Path $EventArgs.FullPath -PathType Container)
    {
        Write-Host "New directory created: $($EventArgs.FullPath)"  
        # run your code/script here
    }
}
于 2012-05-10T08:19:32.150 に答える