内置模块:shutil
作者:互联网
内置模块:shutil
import os import shutil # 删除文件或文件夹 """ os.remove(路径) """ abs_path = os.path.abspath(__file__) superior = os.path.dirname(abs_path) file_path = os.path.join(superior,'files','p2.xlsx') os.remove(file_path) # 删除文件夹或文件 # shutil.rmtree(file_path) # 只能删除文件夹,不能删除文件
import os import shutil abs_path = os.path.abspath(__file__) superior = os.path.dirname(abs_path) file_path = os.path.join(superior,'files') # 拷贝文件夹 shutil.copytree(file_path,r'E:\py学习资料\模块作业\img')
import os import shutil abs_path = os.path.abspath(__file__) superior = os.path.dirname(abs_path) file_path = os.path.join(superior,'files','my.ini') # 拷贝文件 shutil.copy(file_path,r'E:\py学习资料\模块作业\img.ini')
import os import shutil abs_path = os.path.abspath(__file__) superior = os.path.dirname(abs_path) file_path = os.path.join(superior,'files','my.ini') # 文件或文件夹从命名 shutil.move(file_path,r'E:\py学习资料\模块作业\files\mimg.ini')
标签:__,内置,模块,abs,file,path,shutil,os 来源: https://www.cnblogs.com/xialiang37/p/14981659.html