전산Tip

[vbs] 파일내에 문자열 치환하기

모던아트 2021. 4. 13. 22:23
반응형

// replace용 vbs 파일 생성 (파일명 : replace.vbs)

 

Const ForReading = 1
Const ForWriting = 2
strFilenName = Wscript.Arguments(0)

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(strFilenName, ForReading)
strText = objFile.ReadAll

objFile.Close

 

strNewText = strText

 

'변경할 문자열 등록

strNewText = Replace(strNewText, "AAAA" , "BBBB" )

strNewText = Replace(strNewText, "CCCC" , "DDDD" )

 

Set objFile = objFSO.OpenTextFile(strFilenName, ForWriting)

objFile.Write strNewText

objFile.Close

 

 

 

// cmd창에서 replace.vbs를 실행하여 파일내에 문자열 치환

 

cscript replace.vbs "파일명"