Python 파일 이름 변경.

os.rename('원래파일', '변경할 파일')

-> 파일 경로와 파일명 지정 후, 변경할 파일 경로 및 파일이름 확장자

ex) os.rename('path/파일명.확장자', 'path/변경할파일명.확장자')


import os


# 원본 데이터셋 폴더 접근.

input_path_1 = r'E:\deep_learning\handwrittenmathsymbols\data\extracted_images\+'

file_list_input_1 = os.listdir(input_path_1)


# 파일_네임_번호

idx = 0

# 원본 파일 순회하며 -> 파일 리네임.

for i in file_list_input_1:

    idx += 1

    os.rename(r'E:\deep_learning\handwrittenmathsymbols\data\extracted_images\+\{0}'.format(i),r'E:\deep_learning\handwrittenmathsymbols\data\test\+\+_{0}.jpg'.format(idx))


+ Recent posts