Search code examples
batch-filecmdrenamedirectoryfindstr

batch code to chnage folders name after read text files


Someone great in this site give me this code at batch change folder name by read line from text file

@echo off
pushd "your root location"  
for /f "tokens=1* delims=:" %%A in (  
'findstr /srbc:"SMTP_Email_Address  *type=SZ  *[^ ][^ ]*@[^ ][^ ]*\.[^ ][^ ]*  *SMTP_Email_Address" filel.txt^|sort /r'  
) do if exist "%%A" for %%F in ("%%A\..") do (  
  for /f "tokens=3" %%N in ("%%B") do ren "%%~fF" "%%N"  
)  
popd

the code find this code perfectly

SMTP_Email_Address type=SZ name@company.com SMTP_Email_Address

I want the code find this

<SMTP_Email_Address type="SZ">abc@abc.com</SMTP_Email_Address>

because of this signs > < "" the code not work

and change the folder name by the email found in the text file inside


Solution

  • i think i understand the question. you need to escape the special characters with the caret sign (^) e.g. replace

    "SMTP_Email_Address  *type=SZ  *[^ ][^ ]*@[^ ][^ ]*\.[^ ][^ ]*  *SMTP_Email_Address"
    

    with

    "^<SMTP_Email_Address  *type=^"SZ^"^>  *[^ ][^ ]*@[^ ][^ ]*\.[^ ][^ ]*  *^<^/SMTP_Email_Address^>"