Q:

Script for modify file content in specified files

I tried searching previous questions but none worked or I couldn't adapt them to my needs
I want to write a script that asks for:

folder
criteria
old string
new string

And replace every file in the specified folder and subfolders (and force user to type one) with specific criteria (for example, it must be a ".cue" file), and:

If the file is "read only", disable it
search for specified old string into the file content and replace it with new string , and save changes in same file
If the file was "read only", enable it again 

I have this progress , but I don't know that to do in the "do" part:
@echo off 

setLocal enableDELAYedexpansion

:START
set "var2="
set /P var2="type folder "

if "%var2%"=="" goto ERROR

set /p old="old string ? "
set /p new="new string ? "
set /p files="what criteria ? "
echo modifying files...

for /r "%var2%" %%v in (%%files) do (

???

)
pause

goto START

:ERROR
echo type something!!
goto START

A:

The Batch file below do what you want, it requires my FindRepl.bat file that you must copy from this site
@echo off 

setLocal EnableDelayedExpansion

:START
set "var2="
set /P var2="type folder "

if "%var2%" == "" goto ERROR

set /p old="old string ? "
set /p new="new string ? "
set /p files="what criteria ? "
echo modifying files...

for /r "%var2%" %%v in (*%files%) do (
   for /F "delims=" %%a in ('attrib "%%v"') do (
      set "attrib=%%a"
      set "attrib=!attrib:~0,10!"
      if "!attrib:R=!" neq "!attrib!" (
         attrib -R "%%v"
         set attrib=+R
      ) else (
         set attrib=-R
      )
   )
   call FindRepl "%old%" "%new%" < "%%v" > "%%v.tmp"
   move /Y "%%v.tmp" "%%v"
   attrib !attrib! "%%v"
)
pause

goto START

:ERROR
echo type something!!
goto START

You must note that the "old" string is a "regular expression" as described in FindRepl.bat documentation, so you must escape any period with backslash. For example, you must enter "\.wav" in order to search for ".wav" string!

