import os path = 'F:/a.txt' # 文件路径 if os.path.exists(path): # 如果文件存在 # 删除文件,可使用以下两种方法。 os.remove(path) #os.unlink(path) else: print('no such file:%s'%my_file) # 则返回文件不存在
python将文件删除
最新推荐文章于 2024-02-03 05:30:00 发布
import os path = 'F:/a.txt' # 文件路径 if os.path.exists(path): # 如果文件存在 # 删除文件,可使用以下两种方法。 os.remove(path) #os.unlink(path) else: print('no such file:%s'%my_file) # 则返回文件不存在