2017-04-05 5 views
0

이 코드를 사용하여 파일 서버의 파일 이름 변경을 모니터링 해 보았습니다. 그러나 확장 기능이 변경 될 때만 이벤트를 트리거하고 싶습니다.Powershell : 파일 이름 변경을위한 FileSystemWatcher

의견이 있으십니까?

### SET FOLDER TO WATCH + FILES TO WATCH + SUBFOLDERS YES/NO 
$watcher = New-Object System.IO.FileSystemWatcher 
$watcher.Path = "E:\" 
# $watcher.Filter = "*.*" 
$watcher.IncludeSubdirectories = $true 
$watcher.EnableRaisingEvents = $true 

$action = { $path = $Event.SourceEventArgs.FullPath 
      $changeType = $Event.SourceEventArgs.ChangeType 
      $Name = $Event.SourceEventArgs.Name 
      $logline = "$(Get-Date), $changeType, $path, $name" 
      Add-content "E:\log.txt" -value $logline 
      } 

Register-ObjectEvent $watcher "Renamed" -Action $action 
while ($true) {sleep 5} 
+0

미래에는 powershell 관련 질문에 powershell 태그를 추가하는 것이 좋습니다. 여기 지식이 많은 파워 쉘 사용자가 많이 있으며, 그들이 당신을 더 빨리 도울 수 있도록 도와 줄 것입니다! – Persistent13

답변

0

$ watcher 변수의 NotifyFilter 속성을 FileName으로 설정하십시오.

$watcher.NotifyFilter = 'FileName' 

이제 작업을 수행하면 파일 이름이 변경됩니다.