import shutil #파이썬 내장
shutil.copy(src, dst)
shutil.copyfile(src, dst)
shutil.copy2(src, dst)
import shutil
import os
file_name = r'test_txt.txt'
file_path_1 = r'C:\Users\jaegyeong\Desktop\Shutil_1'
file_path_2 = r'C:\Users\jaegyeong\Desktop\Shutil_2'
file1 = os.path.join(file_path_1, file_name)
file2 = os.path.join(file_path_2, file_name)
shutil.copy(file1, file2) #1
shutil.copyfile(file1, file2) #2
shutil.copy2(file1, file2) #3
shutil.copytree(src, dst)
folder_path_1 = r'C:\Users\jaegyeong\Desktop\Shutil_1'
folder_path_2 = r'C:\Users\jaegyeong\Desktop\Shutil_3'
shutil.copytree(folder_path_1, folder_path_2)
ㄴ Shutil_3 폴더가 없으면, Shutil_3 폴더 생성 후 Shutil_1 폴더와 하위 폴더와 파일들이 모두 복사
< dst >가 이미 존재하는 경우, 에러 발생(덮어쓰기 불가)
ㄴ덮어쓰고 싶은 경우 아래 모듈과 함수 사용
from distutils.dir_util import copy_tree
copy_tree(src, dst)
from distutils.dir_util import copy_tree
folder_path_1 = r'C:\Users\jaegyeong\Desktop\Shutil_1'
folder_path_2 = r'C:\Users\jaegyeong\Desktop\Shutil_3'
copy_tree(folder_path_1, folder_path_2)
shutil.move(src, dst)
folder_path_1 = r'C:\Users\jaegyeong\Desktop\Shutil_1\test_txt.txt'
folder_path_2 = r'C:\Users\jaegyeong\Desktop\Shutil_2'
shutil.move(folder_path_1, folder_path_2)
shutil.move(src, dst)
folder_path_1 = r'C:\Users\jaegyeong\Desktop\Shutil_1'
folder_path_2 = r'C:\Users\jaegyeong\Desktop\Shutil_2'
shutil.move(folder_path_1, folder_path_2)
folder_path_1 = r'C:\Users\jaegyeong\Desktop\Shutil_1'
folder_path_2 = r'C:\Users\jaegyeong\Desktop\Shutil_2\Shutil_3'
shutil.move(folder_path_1, folder_path_2)
shutil.rmtree(삭제할_폴더)