Ordner überwachen, Inhalt der Datei ändern, Datei verschieben
Hallo,
ich habe eine Bitte an Euch.
Ich möchte einen Ordner überwachen und sobald eine Textdatei reinkommt, soll in dem Inhalt der Datei ein Zeichen "§" ins "|" geändert werden. Anschliessend soll die Datei in einen anderen Ordner verschoben werden.
Windows Powershell oder Batch. Was wäre das bessere vorgehen und wie?
Vielen lieben Dank.
Ich habe das versucht, aber es klappt nicht so wie es soll:
#script need to search in ersetzungspfad, then raplace and then write to new folder with same name but with end .txt and not .dat
$ersetzungspfad = "C:\Users\Lager\Desktop\Versanddaten\*.dat"
$Ausgabepfad = "C:\Users\Lager\Desktop\Versanddaten\pixi-import\*.txt"
foreach ($s in $search){
Get-ChildItem -Path $ersetzungspfad -Include *.DAT | Foreach-Object {Get-Content $_ | Out-String | Foreach-Object {$_.Replace(„§“,“|“)} | Out-File -FilePath $Ausgabepfad }
ich habe eine Bitte an Euch.
Ich möchte einen Ordner überwachen und sobald eine Textdatei reinkommt, soll in dem Inhalt der Datei ein Zeichen "§" ins "|" geändert werden. Anschliessend soll die Datei in einen anderen Ordner verschoben werden.
Windows Powershell oder Batch. Was wäre das bessere vorgehen und wie?
Vielen lieben Dank.
Ich habe das versucht, aber es klappt nicht so wie es soll:
#script need to search in ersetzungspfad, then raplace and then write to new folder with same name but with end .txt and not .dat
$ersetzungspfad = "C:\Users\Lager\Desktop\Versanddaten\*.dat"
$Ausgabepfad = "C:\Users\Lager\Desktop\Versanddaten\pixi-import\*.txt"
foreach ($s in $search){
Get-ChildItem -Path $ersetzungspfad -Include *.DAT | Foreach-Object {Get-Content $_ | Out-String | Foreach-Object {$_.Replace(„§“,“|“)} | Out-File -FilePath $Ausgabepfad }
Please also mark the comments that contributed to the solution of the article
Content-Key: 665836
Url: https://administrator.de/contentid/665836
Printed on: April 20, 2024 at 11:04 o'clock
7 Comments
Latest comment
while($true){
ls 'C:\Users\Lager\Desktop\Versanddaten' -File -Filter *.dat | %{
(gc $_.Fullname) -replace '§','|' | sc $_.Fullname
$_ | move-item -Destination "C:\Users\Lager\Desktop\Versanddaten\pixi-import\$($_.Name -replace '\.dat$','.txt')" -verbose
}
sleep 5
}
while($true){
ls 'C:\Users\Lager\Desktop\Versanddaten' -File -Filter *.dat | %{
$txt = gc $_.Fullname
$txt = $txt -replace '§','|'
$txt = $txt -replace '(.*101.*)','$112345'
$txt = $txt -replace '(.*5301.*)','$1654321'
$txt | sc $_.Fullname
$_ | move-item -Destination "C:\Users\Lager\Desktop\Versanddaten\pixi-import\$($_.Name -replace '\.dat$','.txt')" -verbose
}
sleep 5
}
Super Aussage und sowas in nem Admin Forum ! Kopfklatsch.
Funktioniert einwandfrei, getestet....
Funktioniert einwandfrei, getestet....