Python C 有没有办法等待os.unlink()或os.remove()完成?
发布时间:2023-12-17 03:17:54 所属栏目:Python 来源:DaWei
导读: 我有以下代码:
os.remove('_Temp_Dir_main' + str(i) + '.exe')
os.rmdir('_Temp_Dir_')
这给了我:
OSError: [WinError 145] Directory is not empty: '_Temp_Dir_'
如果
os.remove('_Temp_Dir_main' + str(i) + '.exe')
os.rmdir('_Temp_Dir_')
这给了我:
OSError: [WinError 145] Directory is not empty: '_Temp_Dir_'
如果
|
我有以下代码: os.remove('_Temp_Dir_main' + str(i) + '.exe') os.rmdir('_Temp_Dir_') 这给了我: OSError: [WinError 145] Directory is not empty: '_Temp_Dir_'如果我把线 time.sleep(0.05)在os.rmdir()之前,它可以正常工作.我认为os.remove()不够快,无法删除文件.有什么方法可以等待它完成它的工作吗? 解决方法 使用 shutil.rmtree()删除目录,不用担心删除文件: import shutil shutil.rmtree('_Temp_Dir_')os.remove()工作正常(在文件删除完成之前不会返回),该目录中必须有其他文件,该进程留下并在sleep()调用期间被删除. (编辑:南阳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python C 如何在TensorFlow中实现递归神经网络?
- Python’的奇怪行为是’运算符,如果与’in’结合使用[复制]
- python-2.7 – OpenCV:libdc1394错误:无法初始化libdc139
- python – 如何使用输入函数和def函数?
- 从Python中删除URL中的utm_ *参数
- python – Pip默认行为与virtualenv冲突?
- python C igraph:为什么add_edge函数如此缓慢地对add_edge
- Python – 对乱码字中的字进行高效狩猎
- 从Python dir()调用模块
- python – 大型Pandas Dataframe并行处理
推荐文章
站长推荐
