调用os.rename()时出错:“该进程无法访问该文件,因为另一个进程正在使用该文件”

2024-04-19 06:03:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图使用脚本in this wonderful medium post从一堆pdf中提取一些文本。我在os.rename()上的pdf_extract函数中发现一个错误,其内容如下:

该进程无法访问该文件,因为另一个进程正在使用该文件:“C:\somepath\someppmfilename.ppm”->;”C:\somepath\image0-0.ppm''

但是我想不出这个文件是在哪里打开的。有什么提示吗

def pdf_extract(myFile, i PATH):        
    print("extracting from file:", myFile)        
    delete_ppms(PATH)        
    images = pdf2image.convert_from_path(PATH + myFile, output_folder=PATH)        
    j = 0        
    for file in sorted (os.listdir(PATH)): 
         if '.ppm' in file and 'image' not in file:
              os.rename(PATH + myFile, PATH + 'image' + str(i) + v'-' + str(j) + '.ppm'
              j += 1
    j = 0
      

1条回答
网友
1楼 · 发布于 2024-04-19 06:03:41

选择开始→键入以搜索“资源监视器” 在CPU选项卡中查找“关联句柄” 搜索您的进程路径

如何打开资源监视器。
https://en.m.wikipedia.org/wiki/Resource_Monitor

相关问题 更多 >