- 0
- 이니스프리
- 조회 수 1614
from string import ascii_lowercase
from random import choice, randint, random
import os
def randomize_files(dir):
for f in os.listdir(dir):
path = os.path.join(dir, f)
if os.path.isfile(path):
ext = os.path.splitext(f)[1]
newname = os.path.join(dir, ''.join([choice(ascii_lowercase) for _ in range(randint(5, 8))]))
newpath = newname + ext
os.rename(path, newpath)
print("rename {} to {}".format(path, newpath))
randomize_files('폴더명을 입력하세요')
https://stackoverflow.com/a/56193729
여기에 있는 방법을 참고했어요~
다만 위 방법은 확장자가 사라지는 문제가 있어서 os.path.splitext()로 그 문제를 해결했네요 ^^
셔플 기능을 만들 때 이런 방법을 응용할 수 있겠죠!
작성자
댓글 0
권한이 없습니다.




