首先我做了新的腳本,使正則表達式:加入兩個腳本
$input_path = 'C:\site-download\input.txt'
$output_file = 'C:\site-download\output.txt'
$regex = '(?<month>VPIP<\/span><span class=""right"">\d{2}.\d{1})'
$regex2 = '(?<month>Winrate<\/span><span class=""right"">\d{1}.\d{1})'
$regex3 = '(?<month>PFR<\/span><span class=""right"">\d{2}.\d{1})'
$regex4 = '(?<month>Winnings<\/span><span class=""right"">\-[0-9]{1,9})'
$regex5 = '(?<month>3Bet<\/span><span class=""right"">\d{1}.\d{1})'
Select-String -Path $input_path -Pattern $regex -List | % { $_.Matches} | % { $_.Value } | Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex2 -List | % { $_.Matches} | % { $_.Value } |Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex3 -List | % { $_.Matches} | % { $_.Value } | Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex4 -List | % { $_.Matches} | % { $_.Value } |Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex5 -List | % { $_.Matches} | % { $_.Value } | Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
其良好到目前爲止工作。
第二個腳本我在網絡上找到的(也工作好):
Function Register-Watcher {
param ($folder)
$filter = "*.*" #all files
$watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $false
EnableRaisingEvents = $true
}
$changeAction = [scriptblock]::Create('
# This is the code which will be executed every time a file change is detected
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file $name was $changeType at $timeStamp"
')
Register-ObjectEvent $Watcher "Changed" -Action $changeAction
}
Register-Watcher "C:\site-download"
所以基本上我的工作,找出如何添加一個腳本來第二。 我想這事:
Function Register-Watcher {
param ($folder)
$filter = "*.*" #all files
$watcher = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
IncludeSubdirectories = $false
EnableRaisingEvents = $true
}
$changeAction = [scriptblock]::Create('
# This is the code which will be executed every time a file change is detected
$path = $Event.SourceEventArgs.FullPath
$name = $Event.SourceEventArgs.Name
$changeType = $Event.SourceEventArgs.ChangeType
$timeStamp = $Event.TimeGenerated
Write-Host "The file $name was $changeType at $timeStamp"
$input_path = $name
$output_file = 'C:\site-download\output.txt'
$regex = '(?<month>VPIP<\/span><span class=""right"">\d{2}.\d{1})'
$regex2 = '(?<month>Winrate<\/span><span class=""right"">\d{1}.\d{1})'
$regex3 = '(?<month>PFR<\/span><span class=""right"">\d{2}.\d{1})'
$regex4 = '(?<month>Winnings<\/span><span class=""right"">\-[0-9]{1,9})'
$regex5 = '(?<month>3Bet<\/span><span class=""right"">\d{1}.\d{1})'
Select-String -Path $input_path -Pattern $regex -List | % { $_.Matches} | % { $_.Value } | Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex2 -List | % { $_.Matches} | % { $_.Value } |Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex3 -List | % { $_.Matches} | % { $_.Value } | Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex4 -List | % { $_.Matches} | % { $_.Value } |Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
Select-String -Path $input_path -Pattern $regex5 -List | % { $_.Matches} | % { $_.Value } | Foreach-Object {$_ -replace '</span><span class=""right"">', ' = '} | Add-Content $output_file
')
Register-ObjectEvent $Watcher "Changed" -Action $changeAction
}
Register-Watcher "C:\site-download"
但不斷收到一些錯誤:
Select-String : Cannot bind argument to parameter 'Path' because it is null. At line:1 char:21 + select-string -Path $input_path -Pattern $regex -List | % { $_.Matches} | % { $_ ... + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Select-String], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SelectStringCommand
有人能幫我解決這個最後的腳本?
「一些錯誤。」 - 。?其錯誤,並在那裏 –
請不要發佈的屏幕截圖錯誤消息,特別是不在某些外部網站上這可能會在任何時候消失。將錯誤消息文本複製並粘貼到您的問題中。 –
對不起。 錯誤代碼: Select-String:無法將參數綁定到參數'Path',因爲它爲空。 在線:1 char:21 + select-string -Path $ input_path -Pattern $ regex -List | %{$ _。匹配} | %{$ _ ... + ~~~~~~~~~~~ + CategoryInfo:InvalidData:(:) [選擇字符串],ParameterBindingValidationException + FullyQualifiedErrorId:ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.SelectStrin gCommand – Elx