homedir, file copy

ecu_jon hayesjdno3 at yahoo.com
Sun Jan 30 21:41:54 EST 2011


On Jan 30, 8:25 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> On 31/01/2011 00:18, ecu_jon wrote:
>
>
>
> > On Jan 30, 7:09 pm, MRAB<pyt... at mrabarnett.plus.com>  wrote:
> >> On 30/01/2011 23:43, 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)
>
> >> shutil.copy(...) copies files, not directories. You should use
> >> shutil.copytree(...) instead.
>
> > i will, closer towards the end.
> > just wanted to get past the naming stuff, the problem above.
> > right now i just want to see it move files from 1 place to another.
> > i had copytree in before, and will go back to that for final version.
> > im working on a backup program, and copytree looks yummy.
>
> > still no idea why getting permission denied.
>
> The path given by backupdir1 is a directory, so you're trying to use
> shutil.copy(...) to copy a directory.
>
> The reason that it's complaining about permissions is that shutil.copy
> is trying to open the source file (look at the traceback) so that it
> can copy the file's contents, but it's not a file, it's a directory.
>
> CPython is written in C, so it's probably the underlying C library
> which is reporting it as a permissions problem instead of a "that's not
> a file!" problem. :-)

as for testing i was planning on using something like this
http://docs.python.org/library/shutil.html
scroll down to 10.10.1.1



More information about the Python-list mailing list