shutil.copyfileobj(fsrc, fdst[, length]) #Copy the content of the file to another file, you can part of the content
import shutil f1=open('test1',encoding='utf-8') f2=open('test2','w',encoding='utf-8') shutil.copyfileobj(f1,f2)
shutil.copyfile(src, dst) #copy file
shutil.copyfile('test1','test2') #A
file that does not exist will create a file without reporting an error
shutil.copymode(src, dst) #Only copy permissions. Contents, groups, users remain unchanged
shutil.copymode( ' test1 ' , ' test2 ' ) #A
file that does not exist will report an error
shutil.copystat(src, dst) #Copy status information, including: mode bits, atime, mtime, flags
shutil.copystat( ' test1 ' , ' test2 ' ) #A
file that does not exist will report an error
shutil.copy(src, dst) #copy files and permissions
shutil.copy( ' test1 ' , ' test3 ' ) #If
a file does not exist, it will create a file without reporting an error
shutil.copy2(src, dst) #Copy files and status information
shutil.copy2( ' test1 ' , ' test4 ' ) #A
file that does not exist will create a file without reporting an error
shutil.copytree(src, dst, symlinks=False, ignore=None) #Recursively copy files
shutil.copytree ( ' test ' , ' new_test ' )
shutil.rmtree(path[, ignore_errors[, onerror]]) #Recursively delete files
shutil.rmtree( ' new_test ' )
shutil.move(src, dst) #Recursively move files
shutil.move( ' test ' , ' test2 ' )
shutil.make_archive(base_name, format,...) #Create a compressed package and return the file path, for example: zip, tar
- base_name: The file name of the compressed package, or the path of the compressed package. If it is only the file name, it will be saved to the current directory, otherwise it will be saved to the specified path
- format: the type of compressed package, "zip", "tar", "bztar", "gztar"
- root_dir: Folder path to be compressed (default current directory)
- owner: user, default current user
- group: group, default current group
- logger: used to record logs, usually a logging.Logger object
shutil.make_archive('shutil_archive_test','zip',r'C:/Users/administered/PycharmProjects')