3
I want to find string e.g. "date" from my files of a folder which contains multiple ".c" and ".h" files in it and replace it with "date 24-April-2018" using batch file. what should do? Please see below code. I want to do the same but not for one file Input.txt , I want to do for multiple files with extensions of a folder
@echo off
setlocal enableextensions disabledelayedexpansion
set "search=@date"
set "replace=@date 24-apr-2018"
set "textFile=Input.txt"
for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%textFile%" echo(!line:%search%=%replace%!
endlocal
)
1If you define
textFile
byset "textFile=%1"
, then you can call this batch file (eg namedSetDate.cmd
) to update the file in the passed parameter. Then you can usefor %i in (DirPath\FileMask) do call SetDate.cmd %i
, doubling the%
if it is in a batch file itself. – AFH – 2018-04-25T11:33:17.987I didn't get you.can you please give me within the batch file solution? – Meera – 2018-04-25T12:09:06.653
I recently started using GrepWin to find and replace across multiple text files and locations. I've been impressed with it.
– Andi Mohr – 2018-04-25T12:34:52.177@Meera - I don't know what else I can say to explain, without going into the sort of detail that would require an answer. If your batch file is
SetDate.cmd
, edit it so that the thirdset
command becomesset "textFile=%1"
, then call it withfor %f in (DirPath\FileMask) do call SetDate.cmd %f
from the command line orfor %%f in (DirPath\FileMask) do call SetDate.cmd %%f
within another batch file. I hope it's clear whatDirPath
andFileMask
signify. – AFH – 2018-04-25T21:04:43.493