Language/python

[Python] 디렉토리 파일들을 다른 디렉토리로 모두 이동하기

MOMOBOB 2021. 12. 27. 19:21
반응형
 # -*- coding: utf8 -*- 
import os
import shutil
import sys

path = '/Users/***/Desktop/test/src/'
files = os.listdir(path)

new_path = '/Users/***/Desktop/test/dir/'

if not os.path.exists(new_path):
    os.mkdir(new_path)
    

for file in files:
    shutil.move(path + file, new_path + file)
  •  # -*- coding: utf8 -*-  : 한글사용을 위한 인코딩 Python3은 필요없음
반응형