【发布时间】:2018-05-11 14:22:33
【问题描述】:
对于了解 Powershell 的人来说,这可能是一个简单的问题。我已经尝试过实现类似问题的几个答案的建议,例如these和these。我有一个文件监视器,它监视文件夹并在发生更改时写入日志文件。这很好用。
我没能做的是执行一个额外的 Python 脚本。我很感激任何建议。
$folder = 'F:\myPath\myFolder' # Enter the root path you want to monitor.
$filter = '*.*' # You can enter a wildcard filter here.
# In the following line, you can change 'IncludeSubdirectories to $true if required.
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
# Registered events:
Register-ObjectEvent $fsw Renamed -SourceIdentifier FileRenamed -Action {
$OldName = $Event.SourceEventArgs.OldName
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file '$name' was $changeType at $timeStamp" -fore white
Out-File -FilePath F:\myPath\myLogFile.txt -Append -InputObject "The file $name was $changeType at $timeStamp"
python F:\myPath\myPythonScript.py}
如何使用 Powershell ISE 实现这一目标?
【问题讨论】:
标签: powershell filesystemwatcher