在python中复制文件:权限被拒绝

时间:2012-11-28 19:45:34

标签: python file permissions transfer denied

  

可能重复:
  Request UAC elevation from within a Python script?

我必须将文件(Say a txt)复制到System文件夹,有没有办法做到这一点?

这是我用于正常文件传输的代码,它起作用了:

import os

import shutil

fileList = os.listdir('J:\hawa')

fileList = ['J:\hawa'+ '\lol.txt']

for f in fileList:
    shutil.copy2(f, 'C:\Windows\System32\Drivers\etc')

但是当目标目录是系统文件夹时,会出现错误:

Traceback (most recent call last):
 File "C:/Python27/copy2.py", line 8, in <module>
 shutil.copy2(f, 'C:\Windows\System32\Drivers\etc')
 File "C:\Python27\lib\shutil.py", line 128, in copy2
 copyfile(src, dst)
 File "C:\Python27\lib\shutil.py", line 83, in copyfile
 with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: 'C:\\Windows\\System32\\Drivers\\etc\\lol.txt'

我可以通过某种方式修改代码,使其以管理员权限运行吗?

0 个答案:

没有答案