2016-07-24 28 views
0

Zuerst habe ich neues Skript, das regex machen:Joining zwei Skripte

$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 

Seine Arbeit so weit gut.

Zweite Skript, das ich in Web gefunden (auch arbeiten gut):

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" 

Also im Grunde, um herauszufinden, ich arbeite, wie ich die erste Skript hinzufügen kann Sekunde. Ich habe versucht, etwas dieses:

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" 

Aber halten einige Fehler bekommen:

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.Sel‌​ectStringCommand

Kann jemand mir helfen, dieses letzte Skript zu beheben?

+2

„einige Fehler.“ -...?, welche Fehler und wo –

+0

Bitte schreiben Sie keine Screenshots Fehlermeldungen, und insbesondere nicht auf einer externen Website das kann jederzeit verschwinden. Kopieren Sie den Text der Fehlermeldung und fügen Sie ihn in Ihre Frage ein. –

+0

Entschuldigung dafür. Fehlercode: Select-String: Das Argument kann nicht an den Parameter 'Path' gebunden werden, da es null ist. In Zeile: 1 Zeichen: 21 + select-string -Pfad $ input_path -Pattern $ regex -List | % {$ _. Treffer} | % {$ _ ... + ~~~~~~~~~~~ + CategoryInfo: invalidData: (:) [Select-String], ParameterBindingValidationException + FullyQualifiedErrorId: ParameterArgumentValidationErrorNullNotAllowed, Microsoft.PowerShell.Commands.SelectStrin gCommand – Elx

Antwort

0

Ihr Regex-Skript enthält einzelne Anführungszeichen ('), die den Skriptblock unterbrechen. . Ersetzen Sie sie durch doppelte Anführungszeichen (")

+0

Bearbeiten Sie Ihre PowerShell auch mit einer ISE wie PowerShell ISE? Ich habe Ihren Code in eine ISE eingefügt und der Fehler wurde sofort angezeigt. –

+0

Ich versuche Power-Shell-ISE. – Elx

+0

Einzelne Anführungszeichen (') wurden entfernt, funktionieren aber immer noch nicht wie gewünscht. – Elx

0

Was ich jetzt getestet:

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 "Created" -Action $changeAction 
} 


Register-Watcher "C:\site-download" 

Function regex-inout { $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 

} regex-inout 

Folder Watch gute Arbeits Aber wo sollte ich Funktion regex-inout bewegen, so dass, wenn neue Dateien kommen dann diese in den Ordner. REGEX Arbeit beginnen nur Ordner Uhr Im Moment arbeiten und Regex nichts nicht tun

Sorry für mein schlechtes Englisch