본문 바로가기
파이썬

파이썬 파일이름 변경하기 정리

by 바나나하나 2019. 4. 1.
반응형

rfind()

string = "Hello there"

string.rfind('찾고자하는 문자', 처음위치, 마지막 위치)

찾는 문자열 중에 가장 끝에 있는 위치를 반환한다

 

os.listdir(path) # 파일목록전달

    os.chdir(path) # 작업하고 있는 디렉토리 변경

    os.getcwd() # 현재 프로세스의 작업 디렉토리 얻기

    os.path.abspath(filename) # 파일의 상대 경로를 절대 경로로 바꾸는 함수

    os.path.exists(filename) # 주어진 경로의 파일이 있는지 확인하는 함수

    os.curdir() # 현재 디렉토리 얻기

    os.pardir() # 부모 디렉토리 얻기

    os.sep() # 디렉토리 분리 문자 얻기

    os.path.basename(filename) # 파일명만 추출

    os.path.dirname(filename) # 디렉토리 경로 추출

    os.path.split(filename) # 경로와 파일명을 분리

    os.path.join(path,path) # \\패턴으로 경로를 만들어줌

    os.path.splitdrive(filename) # 드라이브명과 나머지 분리 (MS Windows의 경우)

    os.path.splitext(filename) # 확장자와 나머지 분리

    shutil.copy(path, newPath) # 파일 복사

    shutil.copy2(path, newPath) # 파일 복사 (설정값도 함께 복사)

    shutil.move(path, newPath) # 파일 이동줌



출처: https://man-about-town.tistory.com/44 [YongWook's Notes]

 

path 관련 자료

https://devanix.tistory.com/298

 

파이썬 – os.path 모듈

◎ os.path는 파일 경로를 생성 및 수정하고, 파일 정보를 쉽게 다룰 수 있게 해주는 모듈. os.path.abspath(path) 현재 경로를 Prefix로 하여 입력받은 경로를 절대경로로 바꿔서 반환합니다. >>> abspath('tmp')..

devanix.tistory.com

 

반응형

댓글