windows强制删除文件命令
windows强制删除文件命令:rd/s/q 盘符:\某个文件夹del/f/s/q 盘符:\某个文件#!usr/bin/env python# -*- coding: utf-8 -*-import osdef delete_file(filePath):# 常规操作;使用缺陷如果想要删除文件正在被使用那么就会报异常if os.path.exists(filePath):os.remove(fil
·
windows强制删除文件命令:
rd/s/q 盘符:\某个文件夹
del/f/s/q 盘符:\某个文件
#!usr/bin/env python
# -*- coding: utf-8 -*-
import os
def delete_file(filePath):
# 常规操作;使用缺陷如果想要删除文件正在被使用那么就会报异常
if os.path.exists(filePath):
os.remove(filePath)
# 在某些情况下,我们程序中某些db文件可能因为被打开没有关闭,但是此时我们又想要强制删除
try:
# 强制删除文件
os.system('del/f/s/q {}'.fromat(filePath))
#强制删除文件夹
os.system('rd/s/q {}'.fromat(filePath))
except Exception as e:
print e.message
更多推荐
已为社区贡献1条内容
所有评论(0)