How does the python shutil module operate the file
This article mainly explains the "python shutil module how to operate the file", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "python shutil module how to operate the file" bar!
1. Copy files and folders and call shutil.copy ()
> > import shutil, os > os.chdir ('C:\\ delicious') > shutil.copy ('C:\\ spam.txt','C:\\ delicious')'C:\\ delicious\\ spam.txt' > shutil.copy ('eggs.txt',' C:\\ delicious\\ eggs2.txt')'C:\\ delicious\\ eggs2.txt'
2. The shutil.move () method can change the file name.
> import shutil > shutil.move ('C:\\ bacon.txt','C:\\ eggs')'C:\\ eggs\\ bacon.txt' > shutil.move ('C:\\ bacon.txt','C:\\ eggs\\ new_bacon.txt')'C:\\ eggs\\ new_bacon.txt'
3. The shutil module can delete a folder and all its contents.
Import os for filename in os.listdir (): if filename.endswith ('.rxt'): # os.unlink (filename) print (filename) Thank you for your reading, the above is the content of "how the python shutil module operates the file". After the study of this article, I believe you have a deeper understanding of how the python shutil module operates the file, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!