• 목록
  • 아래로
  • 위로
import os, fnmatch


def folderReplace(find_str, replace_str, filePattern):
    count = 0
    current_file = os.path.basename(__file__)
    for path, dirs, files in os.walk(os.path.dirname(os.path.abspath(__file__))):
        for filename in fnmatch.filter(files, filePattern):
            if filename == current_file:
                continue
            filepath = os.path.join(path, filename)
            with open(filepath, 'rt', encoding='UTF-8') as f:
                s = f.read()
            if s.find(find_str) != -1:
                print(filepath)
                s = s.replace(find_str, replace_str)
                count += 1
                with open(filepath, 'wt', encoding='UTF-8') as f:
                    f.write(s)
    print('total : ' + str(count))

folderReplace('변경 전 단어', '변경 후 단어', '*.변경할 확장자')

 

 

replace 횟수도 출력되고, 스크립트 파일명을 굳이 입력할 필요가 없도록 

 

아래 URL에 올렸던 파일을 조금 개량했어요 ^^

 

https://studyforus.com/tipnknowhow/641299

 

작성자
이니스프리 119 Lv. (0%) 1905150/115200000EXP

Make StudyForUs Great Again!

 

CSVpuymXAAAVVpd.jpg

댓글 0

권한이 없습니다.
번호 제목 글쓴이 날짜 조회 수
공지 [작업 완료] 설 명절 맞이 서버 업데이트 안내 3 마스터 마스터 24.02.11.17:21 710
공지 [중요] 호스팅 만료와 관련하여 일부 수칙이 변경됩니다. 4 마스터 마스터 23.01.14.02:23 4383
486 [Python] 내일 날짜를 구하기 3 이니스프리 이니스프리 21.03.31.23:46 767
485 [Python] 네이트 실시간 검색어 크롤링 1 이니스프리 이니스프리 21.03.22.20:16 1005
484 [Python] 간단하게 내 ip 확인하기 3 이니스프리 이니스프리 21.03.20.00:26 221
483 [Python] 특정 서버와 내 PC 간의 시간 차이를 구하기 (테스트 중) 이니스프리 이니스프리 21.03.20.00:11 1403
482 [Python] Youtube Playlist에 담긴 동영상들을 역순으로 불러오기 이니스프리 이니스프리 21.03.19.00:41 146
481 [미디어위키]웹호스팅상의 미디어위키 사용자들께 대박 좋은 일이 일어났어요! 2 입체그림 21.03.14.10:53 127
480 [Python] 파이썬으로 평균을 구하는 두 가지 방법 이니스프리 이니스프리 21.03.13.21:58 166
479 [Python] 동영상 파일의 재생시간 길이를 구하기 (OpenCV vs MoviePy) 이니스프리 이니스프리 21.03.12.22:33 4638
478 [Python] Youtube_dl 사용시 주의할 점 이니스프리 이니스프리 21.03.12.22:14 128
477 [Python] Youtube Data API를 이용하여 특정 채널의 모든 비디오 링크를 얻는 함수 이니스프리 이니스프리 21.03.12.22:05 388
476 php8.0 대응 라이믹스 오류 해결법 NUBE title: 크롬NUBE 21.03.08.11:39 266
475 [Python] 동영상 파일의 포맷 변환 - FFmpy 모듈 이니스프리 이니스프리 21.03.07.12:14 242
474 [Python] glob.glob() 정렬 방법 정리! 이니스프리 이니스프리 21.03.07.00:49 1500
473 [Python] 윈도우에서 pyaudio 모듈 설치 에러 해결하는 방법 3 이니스프리 이니스프리 21.03.06.15:11 524
472 외국어(인도-유럽어족) 학습에 관하여 4 이니스프리 이니스프리 21.02.21.00:01 122
471 ionicons.com - 오픈 소스 아이콘 4 이니스프리 이니스프리 21.02.14.18:59 307
470 나리야 익명보드 및 내 글 알림 관련 Q&A image 이니스프리 이니스프리 21.02.14.17:30 105
469 [Python] 크롤링한 bytes를 string으로 변환 이니스프리 이니스프리 21.02.14.15:32 109
468 [Python] BeautifulSoup에서 class명에 공백이 있을 때 검색 방법 이니스프리 이니스프리 21.02.13.00:26 2028
467 [Python] Instalooter 에러 발생 시 대처법 1 이니스프리 이니스프리 21.01.31.13:37 215