python - shutil 说子文件夹正在使用中,因此无法移动它并且程序崩溃但一切都已成功移动
问题描述
在我发出移动命令之前,我正在使用 shutil 移动一个文件夹,其中包含我的程序正在使用的一堆东西。此时我关心的所有内容都已从内存中卸载,因此每个文件都按预期成功移动到目标文件夹。神秘地,一个有问题的子文件夹仍然存在(即使在目标位置创建了一个类似的子文件夹)并且程序抛出以下错误:
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:
'C:\\Users\\Ze\\PycharmProjects\\Ploutos\\ProductList\\Unedited\\1005001769427465\\Images'
我要移动的文件夹是编号 ID 1,其中包含有问题的“图像”文件夹。
编辑:据我所知,除了我自己的程序和 Pycharm 正在使用该文件夹之外,没有其他程序。尝试重新索引文件时可能是 Pycharm 吗?
相关代码:
def move_product_to_edited(product_id):
global products_edited_during_session_counter
unedited_products_path = application_path + '\\ProductList\\Unedited\\'
edited_products_path = application_path + '\\ProductList\\Edited\\'
# if the product has not yet been moved, move it
if os.path.exists(unedited_products_path + str(product_id)):
shutil.move(unedited_products_path + str(product_id), edited_products_path + str(product_id))
我该如何尝试进一步调试呢?我不知道如何检查为什么该文件夹仍在使用中。
解决方案
推荐阅读
- scala - How do you overwrite array elements in HOCONS?
- python - 如何使用 sqlalchemy 和 postgres 使用嵌套的 jsonb 进行过滤
- scala - `Seq.contains` 因类型不匹配而失败的替代方法是什么?
- sql - Separate Comma Separated values into different rows
- bash - 对格式化(彩色)文本进行排序
- python - 通过增加数字写入文件
- python - 为什么 str.split(" " 或 ", ") 不给出错误?
- python - ContextualVersionConflict:Datalab + Cloud Vision
- elasticsearch - Elasticsearch——如何在索引中的 json 格式字段上查找特定元素
- ember.js - EmberJS Mirage 依赖属性不会在补丁上更新