homedir, file copy

Dave Angel davea at ieee.org
Sun Jan 30 21:55:19 EST 2011


On 01/-10/-28163 02:59 PM, ecu_jon wrote:
> On Jan 30, 7:19 pm, Dave Angel<da... at ieee.org>  wrote:
>> On 01/-10/-28163 02:59 PM, ecu_jon wrote:
>>
>>> ok now i get permission denied....
>>
>>> import os
>>> homedir =s.path.expanduser('~')
>>> try:
>>>       from win32com.shell import shellcon, shell
>>>       homedir =hell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
>>
>>> except ImportError:
>>>       homedir =s.path.expanduser("~")
>>> print homedir
>>> print os.listdir(homedir+"\\backup\\")
>>> #homedir.replace("\\\\" , "\\")
>>> #print homedir
>>> backupdir1 =s.path.join(homedir, "backup")
>>> backupdir2 =s.path.join(homedir, "backup2")
>>> shutil.copy (backupdir1, backupdir2)
>>
>> You forgot to include the error traceback.
>>
>> So, is homedir/backup a file, or is it a directory?  If you're trying to
>> copy whole directories, you might want to look at copytree instead.
>>
>> If you're not sure, you could use
>>       os.isfile()
>>
>> to check.  If that's false, then shutil.copy() can't work.  Similarly,
>> if the destination is a readonly file, you'd get some error.
>>
>> DaveA
>
> today's date is :  30
> week chosen is :  4
> C:\Users\jon
> ['test1.txt', 'test2.txt']
>
> Traceback (most recent call last):
>    File "D:\spring 11\capstone-project\date.py", line 45, in<module>
>      shutil.copy (backupdir1, backupdir2)
>    File "C:\Python27\lib\shutil.py", line 116, in copy
>      copyfile(src, dst)
>    File "C:\Python27\lib\shutil.py", line 81, in copyfile
>      with open(src, 'rb') as fsrc:
> IOError: [Errno 13] Permission denied: 'C:\\Users\\jon\\backup'
>

Good job, reading the first part of my message.  Now, why are you saying 
in other messages that it can't write to your home directory?  The error 
doesn't refer to your home directory, it refers to a file 
C:\Users\jon\backup which it can't read.

But as your program demonstrates, that's a directory not a file.  It's 
fine to use shutil.copy, but then you have to give it a source file to copy.

For example, C:\Users\jon\backup\test1.txt

DaveA



More information about the Python-list mailing list