My aim is to search for a string contained within multiple .config files that sits inside a directory.
The folder structure is like this: C:\Parent_Folder\child_folder\
The child folder contains many different folders containing a .config file within each folder.
I am trying to create a .bat file that will allow me to search all of these folders and then replace a certain string with a new string.
I have found a way to search all files and print this to a document showing me where the changes are requires using:
findstr /i /s "DATABASE1" *.config > c:\temp\Changes.txt
However when it comes to creating a batch file to search the directory and replace all these files with a new string I am coming across the file path does not exist.
I have had a look at the following similar issues: Batch script to replace specific string in multiple files
Find and replace string in multiple files within a folder using windows Batch script
The code I am currently using is:
@echo off
setlocal enableextensions disabledelayedexpansion
set "dir1=C:\Parent_Folder\child_folder\"
set "search=database1"
set "replace=db2"
for /f "delims=" %%i in ("%dir1%\*.config") do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
>>"%configFile%" echo(!line!
endlocal
)
@pause
The error I keep coming across is that the specified path can not be found, I thought it may be due to environment variables so I added the path in there and displayed the echo %PATH%
in the .bat file and the path does exist however I keep getting the error stating it does not.
So I am not sure if it is actually something else here causing the issue.
Any advice would be great.