목표
폴더내에 확장자명을 일괄적으로 변경하는 코드를 정리하고자 한다.
import os, glob
files = glob.glob("*.png") #-- 변경하려는 확장자명을 가진 파일들을 모두 가져온다.
for file in files:
n_split = os.path.splitext(name) #-- 파일명에서 확장자와 basename을 구분해준다.
os.rename(file, n_split[0]+".jpg") #-- basename에 "jpg" 확장자를 붙이고 파일명을 변경해준다.
반응형
'Language > python' 카테고리의 다른 글
[에러] If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. (0) | 2023.07.11 |
---|---|
[Python] requirements.txt로 패키지 관리 (0) | 2023.06.29 |
[Python] 리스트 안의 원소들을 한번에 int type 으로 변환 (0) | 2023.02.14 |
[Python] Image 읽는 방법 (0) | 2023.02.10 |
[에러] TypeError : can't convert CUDA tensor to numpy (0) | 2023.02.09 |