

根据windows操作系统的特性,删除只读文件是无权限的,必须要先移除只读属性才能删除该文件。
实现删除文件的原理如下:移除文件的只读属性,然后删除目录树。
可以通过python扩展来支持。
具体的实现路径如下:
步骤一、
1添加Python扩展
# 使用提醒:
# 1. xbot包提供软件自动化、数据表格、Excel、日志、AI等功能
# 2. package包提供访问当前应用数据的功能,如获取元素、访问全局变量、获取资源文件等功能
# 3. 当此模块作为流程独立运行时执行main函数
# 4. 可视化流程中可以通过"调用模块"的指令使用此模块
import os
import stat
import shutil
import xbot
from xbot import print, sleep
from .import package
from .package import variables as glv
def _addWritePermForFile(filePath):
if not os.access(filePath, os.W_OK): os.chmod(filePath, stat.S_IWUSR)
def _addWritePermForFiles(rootPath):
if not os.path.exists(rootPath): return
if os.path.isdir(rootPath):
listItems = os.listdir(rootPath)
for item in listItems:
nextPath = os.path.join(rootPath, item)
if (os.path.isfile(nextPath)):
_addWritePermForFile(nextPath)
else:
_addWritePermForFiles(nextPath)
elif os.path.isfile(rootPath):
# called only if rootPath is a file
_addWritePermForFile(rootPath)
def remove(rootPath):
_addWritePermForFiles(rootPath)
if (os.path.isdir(rootPath)):
shutil.rmtree(rootPath)
else:
os.remove(rootPath)
def main(args):
if args is None:
rootPath = "";
else:
rootPath = args.get("rootPath", "")
remove(rootPath)
2 设置流程参数
rootPath 设置为输入参数
3 主流程调用