file/folder naming

Chris Rebert clp2 at rebertia.com
Sat Feb 19 07:36:08 CET 2011


On Fri, Feb 18, 2011 at 10:13 PM, ecu_jon <hayesjdno3 at yahoo.com> wrote:
> ok changed the try/except to just a file copy and got this:
> sourcepath is : [u'I:\\college\\spring11\\capstone-project\
> \facbac-009.py']
> destpath is : V:\week3
> destpath is : V:\week3\facbac-009.py
> Traceback (most recent call last):
>  File "I:\college\spring11\capstone-project\folder.py", line 53, in
> button1Click
>    backupfiles()
>  File "I:\college\spring11\capstone-project\folder.py", line 19, in
> backupfiles
>    shutil.copy2(sourcepath,
> os.path.join(destpath,os.path.basename(files)))
>  File "C:\Python27\lib\shutil.py", line 127, in copy2
>    copyfile(src, dst)
>  File "C:\Python27\lib\shutil.py", line 67, in copyfile
>    if _samefile(src, dst):
>  File "C:\Python27\lib\shutil.py", line 62, in _samefile
>    return (os.path.normcase(os.path.abspath(src)) ==
>  File "C:\Python27\lib\ntpath.py", line 471, in abspath
>    path = _getfullpathname(path)
> TypeError: coercing to Unicode: need string or buffer, list found
>
> yes i see the list.
> but shouldnt this "for files in sourcepath:" parse thru the list ... ?

That doesn't matter when your actual copy2() call still refers to
`sourcepath` (the list):
shutil.copy2(sourcepath, os.path.join(destpath,os.path.basename(files)))
             ^^^^^^^^^^
I presume you want `files` here rather than `sourcepath`.

Incidentally, I think `sourcepath` is poorly named given that it's a
list of paths, and `files` is also poorly named given that it's a
single filepath.

Cheers,
Chris
--
"There are only two hard problems in Computer Science:
    cache invalidation and naming things." – Phil Karlton
http://blog.rebertia.com



More information about the Python-list mailing list