homedir, file copy

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


On 01/-10/-28163 02:59 PM, ecu_jon wrote:
> ok now i get permission denied....
>
> import os
> homedir = os.path.expanduser('~')
> try:
>      from win32com.shell import shellcon, shell
>      homedir = shell.SHGetFolderPath(0, shellcon.CSIDL_APPDATA, 0, 0)
>
> except ImportError:
>      homedir = os.path.expanduser("~")
> print homedir
> print os.listdir(homedir+"\\backup\\")
> #homedir.replace("\\\\" , "\\")
> #print homedir
> backupdir1 = os.path.join(homedir, "backup")
> backupdir2 = os.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






More information about the Python-list mailing list