본문 바로가기
파이썬 언어

Python 으로 폴더안의 텍스트 파일들의 문자열 replace 하기

by treeCoder 2021. 9. 19.

Python 으로 폴더안의 텍스트 파일들의 문자열 replace 하기이다.

# https://stackoverflow.com/questions/50037369/find-and-replace-string-from-multiple-files-in-a-folder-using-python

import glob

for f in glob.glob("*.[ch]"):
    with open(f, "r") as inputfile:
        newText = inputfile.read().replace('Version1', 'Version2.2.1')

    with open(f, "w") as outputfile:
        outputfile.write(newText)

댓글