PermissionError:[Errno 13]权限被拒绝:尝试使用python复制文件时出现“系统卷信息”

PermissionError:[Errno 13]权限被拒绝:尝试使用python复制文件时出现“系统卷信息”,python,Python,我正在尝试创建一个程序,将插入计算机的U盘中的文件复制到硬盘驱动器中的文件夹中。我不断地发现这个错误: PermissionError:[Errno 13]权限被拒绝:“系统卷信息” 代码是 import os import shutil from shutil import copyfile drives = [ chr(x) + ":" for x in range(65,90) if os.path.exists(chr(x) + ":") ] print(drives) if "E:

我正在尝试创建一个程序,将插入计算机的U盘中的文件复制到硬盘驱动器中的文件夹中。我不断地发现这个错误: PermissionError:[Errno 13]权限被拒绝:“系统卷信息” 代码是

import os
import shutil
from shutil import copyfile
drives = [ chr(x) + ":" for x in range(65,90) if os.path.exists(chr(x) + ":") ]
print(drives)


if "E:" in drives:
    with open('backupNumbers.txt', 'r') as f:
        f_contents =f.readlines()
        numberofFolders = int(f_contents[0])
        numberofFolders += 1
    with open('backupNumbers.txt', 'w') as wf:
        wf.write(str(numberofFolders))

    def createFolder(directory):
        try:
            if not os.path.exists(directory):
                os.makedirs(directory)
        except OSError:
            print ('Error: Creating directory. ' +  directory)
    folderNumber = str(numberofFolders)    
    createFolder('./' + "Backup " + folderNumber + '/')
    src = "E:\\"
    dest1 = "Y:\\Documents\\USB Copies\\"
    dest = str(dest1 + "Backup" + folderNumber)
    files = os.listdir(src)
    os.chdir(src)
    for file in files:
        with open(file) as f:
            print(file, f.read())
    for file in files:
        shutil.copy(file, dest)
完整的回溯是

File "<ipython-input-4-fb59bc7c32b6>", line 1, in <module>
    runfile('E:/USB Backups/Automation.py', wdir='E:/USB Backups')

  File "C:\Users\Garret Langlois\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "C:\Users\Garret Langlois\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "E:/USB Backups/Automation.py", line 30, in <module>
    with open(file) as f:

PermissionError: [Errno 13] Permission denied: 'System Volume Information'
系统卷信息是Windows用于管理还原点的特殊文件夹

你可能不需要自己复制它,我建议你跳过它


但是如果你想访问它,你可以在这里阅读:

你能分享整个回溯吗?你混合了两种命名约定,变量和函数名应该遵循小写字母加下划线的样式。这里可能有更多的代码,不需要重现这个问题。尝试删除代码,直到出现显示相同故障的最小程序。例如,关于读取backupNumbers.txt的所有内容都不是必需的。我使用backupNumbers.txt为要命名的文件夹创建了一个参考号,因为我想不出一种方法来添加一个编号,并在代码运行之间引用。我并不是说你不能在你的代码中有它,但它与这个权限错误不太相关。我如何排除它被复制?这取决于你想让程序做什么。一个好的选择可能是捕获、打印并继续处理任何被拒绝权限的错误:请参阅