Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

파이썬에서 바이너리 파일을 어떻게 복사합니까?

<시간/>

Shutil 모듈은 전체 폴더뿐만 아니라 파일을 복사하는 기능을 제공합니다.

shutil.copy(source, destination) 를 호출하면 경로 원본의 파일이 경로 대상의 폴더로 복사됩니다. (소스와 대상 모두 문자열입니다.) 대상이 파일 이름이면 복사된 파일의 새 이름으로 사용됩니다. 이 함수는 복사된 파일의 경로 문자열을 반환합니다.

예를 들어

>>> import shutil
>>> # Copy the file in same folder with different name
>>> shutil.copy('original.txt', 'duplicate.txt')
'/home/username/duplicate.txt'
>>> shutil.copy('original.txt', 'my_folder/duplicate.txt')
'/home/username/my_folder/duplicate.txt'

동일한 프로세스를 사용하여 바이너리 파일을 복사할 수도 있습니다.