Saved Bookmarks
| 1. |
Solve : Replace a specific string all files in a folder? |
|
Answer» I have the following requirement.I need to replace a specific string in all the files with the servername specified in the input parameter of the batch file. in all the files with the servername specified in the input parameter of the batch file I'm guessing that by input parameter you're referring to a command line argument. CODE: [Select]echo off setlocal enabledelayedexpansion for /f %%x in ('dir /a:-d /s /b') do ( for /f "tokens=* delims=" %%i in (%%x) do ( SET input=%%i set input=!input:^<servername^>=%1! echo !input! >> "%%x.chg" ) ) The CHANGED files have .chg appended to the original file name. Batch file is designed to run in the same directory where the files are LOCATED. This can be changed, you never gave any specifics. Pass original server name as a command line argument. If the original server name contains brackets, the code needs to be adjusted. Again you provided no specifics. Good luck. |
|