I have some xml files (about 100, some in subfolders) whose IDs need to be changed. Therefore I have an Excel list with about 1.100 lines, left column is the old ID name and right column the new one which should replace the old one.
I found this script on Stackoverflow (and changed it a little):
@rem replaceids.bat
ECHO off
SETLOCAL enabledelayedexpansion
SET source=%1
SET target=%2
IF EXIST %target% DEL /f %target%
FOR /f "delims=" %%i IN ('FINDSTR . %source%') DO (
SET line=%%i
SET line=!line:ö=oe!
SET line=!line:ä=ae!
SET line=!line:ü=ue!
ECHO !line! >> %target%
)
Here's the original link: batch replace multiple different strings
Then I created another batch file to call the one above and run it through my files:
for /R %%F in (*.xml) do (
replaceids.bat "%%~dpnxF" "C:\mytargetfolder%%~pnxF"
)
Found this on Stackoverflow as well; here's the link: Batch process all files in directory
Also thanks to Meltz014 from reddit, who helped me get this far.
The problem I have now is that it says that the network path can not be found when I start it (not sure what it says exactly in English since I'm not in the office and running it on a German Windows right now). As far as I can see I'm not referencing to any networks.
Any help would be appreciated.
My command line experience is very limited by the way.
EDIT
I just found something else that might get me closer, it still doesn't work yet though: How to Find Replace Multiple strings in multiple text files using Powershell
$Iteration = 0
$FDPATH = 'D:\opt\HMI\Gfilefind_rep'
#& 'D:\usr\fox\wp\bin\tools\fdf_g.exe' $FDPATH\*.fdf
$GraphicsList = Get-ChildItem -Path $FDPATH\*.g | ForEach-Object FullName
$FindReplaceList = Import-Csv -Path $FDPATH\Input.csv
foreach($Graphic in $Graphicslist){
Write-Host "Processing Find Replace on : $Graphic"
foreach($item in $FindReplaceList){
Get-Content $Graphic | ForEach-Object { $_ -replace "$($item.FindString)", "$($item.ReplaceString)" } | Set-Content ($Graphic+".tmp")
Remove-Item $Graphic
Rename-Item ($Graphic+".tmp") $Graphic
$Iteration = $Iteration +1
Write-Host "String Replace Completed for $($item.ReplaceString)"
}
}
It seems to do something, but then after finnishing it always says
String Replace Completed for
My CSV file is created as it is in the example, that means:
FindString ReplaceString
AA1A 171PIT9931A
BB1B 171PIT9931B
etc..
Since it doesn't find anything, I assume something with the CSV might be wrong? Any help would be highly appreciated!