Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created April 24, 2018 12:41
Show Gist options
  • Save developer-sdk/f604e250c6550070bb984b1dd28098fd to your computer and use it in GitHub Desktop.
Save developer-sdk/f604e250c6550070bb984b1dd28098fd to your computer and use it in GitHub Desktop.
python 디렉토리의 파일명 변경하기, rename files
# -*- coding: utf-8 -*-
import sys
from os import rename, listdir
# 현재 위치의 파일 목록
files = listdir('.')
# 파일명에 번호 추가하기
count = 0
for name in files:
# 파이썬 실행파일명은 변경하지 않음
if sys.argv[0].split("\\")[-1] == name:
continue
new_name = name.replace(".", "{0:03d}.".format(count))
rename(name,new_name)
count += 1
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
def rename_file():
# 현재 위치(.)의 파일을 모두 가져온다.
for filename in os.listdir("."):
# 파일 확장자가 (properties)인 것만 처리
if filename.endswith("properties"):
# 파일명에서 AA를 BB로 변경하고 파일명 수정
new_filename = filename.replace("AA", "BB")
os.rename(filename, new_filename)
if __name__ == "__main__":
rename_file()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment