Friday 9 February 2018

find and replace - Script for modifying 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:



  1. If the file is read-only, disable it.

  2. Search for specified old string in the file content and replace it with new string , and save changes in same file.

  3. If the file was read-only, enable it again.


I have this code so far, but I don't know what 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

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...