Python 3 PermissionError:[WinError 32]进程无法访问该文件,因为它正被另一个进程

时间:2018-04-07 13:53:21

标签: python python-3.x file

桌面上有两个文件夹。只要捕获的文件夹中只有一个文件,我想重命名(即剪切和粘贴)到Screenshots文件夹。 但是当我运行程序(任一目录中没有文件)并将一个文件粘贴到src(即Captured文件夹)时,它会抛出一条错误消息。我在这里缺少什么?

import os

dest= 'C:/Users/rajini raja/Desktop/Screenshots/'
src = 'C:/Users/rajini raja/Desktop/Captured/'

while True:
    if len(os.listdir(src)) == 1:
        os.rename(src + 'capture.png', dest + 'capture.png')
        break

错误消息显示为

Traceback (most recent call last):
  File "C:\Users\rajini raja\Desktop\os_rename.py", line 13, in <module> 
os.rename(src + 'capture.png', file_path + 'capture.png')
PermissionError: [WinError 32] The process cannot access the file because it 
is being used by another process: 'C:/Users/rajini 
raja/Desktop/Captured/capture.png' -> 'C:/Users/rajini 
raja/Desktop/Screenshots/capture.png'

0 个答案:

没有答案