I try to find a string "blabla" inside a file. If I find the string I replace it with "bloblo", if not do nothing. And I want to do this operation for all the files that I have in a folder.
When I apply the script on one file, it works well. When I use a for loop it doesn't work. it does not enter inside the for loop
Here is my script:
set "Var1=blabla" set "Var2=bloblo" FOR %%i IN (C:\Users\UserName\Desktop\TEST\*.txt) DO ( find /c "%Var1%" %%i if %errorlevel% equ 1 goto notfound call PathFile\FUNCTION_REPLACE.cmd %Var1% %Var2% %%i :notfound )
I use a script "Function_replace" to replace the values, here is the script:
SetLocal EnableExtensions DisableDelayedExpansion Set "search=%~1" Set "replace=%2" Set "File=%3" For /F "Tokens=1*Delims=]" %%A In ('Find /V /N ""^<"%File%"^&Break^>"%File%"' )Do (Set "line=%%B" SetLocal EnableDelayedExpansion (If Not "%%B"=="" (Echo(!line:%search%=%replace%!)Else Echo()>>"%File%" EndLocal)
I used to use directly the call of my replace function for each files of my folder. But it takes a long time to go inside each file. That's why I want to check before going inside each file, if the string exists or not (by using find /c).
Can you spot where is the issue coming from?