Shutil.copyfile (SRC,DST)
Both SRC and DST must be files, the source file src copied to the destination file DST, if the target file DST exists, the file content will be overwritten; no copy file src; The destination address should have write permission, the exception information thrown is IOException
>> Import Shutil
>> shutil.copyfile ("E:\python\0521.txt", "E:\0521.txt")
>> shutil.copyfile ("E:\python\1.jpg", "e:\1.jpg")
Shutil.copy (SRC,DST)
Copy a file src to DST, and the difference between shutil.copyfile () is that SRC is a file, but DST can be a directory and a file;
If the target file DST exists, the contents of the file will be overwritten; The file src will be copied, the destination address should have write permission, the exception information thrown is IOException
>> shutil.copy ("E:\python\2.txt", "C \")
>> shutil.copy ("E:\python\2.txt", "C:\3.txt")
Shutil.move (SRC,DST)
Move a file or rename a file
You can rename the file src to DST, or you can move the file src to DST
>> shutil.move ("E:\python\2.txt", "E:\python\2-2.txt")
>> shutil.move ("E:\python\2-2.txt", "C:\3-3.txt")
Shutil.copy2 (SRC,DST)
The last access time and modification time of the file are also copied on the basis of copy.
>> shutil.copy2 ("E:\python\222.txt", "C:\222.txt")
Shutil.copytree (olddir,newdir,true/false) Copy the folder and its files
Copy the Olddir to a newdir, if the 3rd parameter is true, the symbol connection under the folder will be kept when the directory is copied, and if the 3rd parameter is false, a physical copy will be generated in the replicated directory instead of the symbolic connection
>> shutil.copytree ("E:\python", "C:\python", False)
>> shutil.copytree ("E:\python", "C:\python2")
Shutil.rmtree (PATH)
Recursively delete all files in a directory and directory
>> shutil.rmtree ("C:\python")
Shutil.copymode (SRC, DST)
It just copies its permissions. Other things are not copied.
Shutil.copystat (SRC, DST)
Copy permissions, last access time, last modified time
The Shutil module in Python