[Tutor] Re: Help with copying files
Charlie Clark
charlie@begeistert.org
Sat, 18 May 2002 19:22:09 +0000
On 2002-05-18 at 16:00:04 [+0000], you wrote:
> def walker(arg, dirname, filenames):
> # Lists directories, files=20
> for filename in filenames:
> path =3D dirname + os.sep + filename
> print path
> newdir =3D dirname[2:]
> os.makedirs('d:\\temp' +newdir)
> shutil.copy(path, 'd:\\temp\downloads')
> file =3D open('test1.txt', 'a')
> file.write(newdir + '\n')
>
> os.path.walk('c:\\downloads', walker, None)
if this is your error:
os.makedirs('d:\\temp' +newdir)
File "C:\Python22\lib\os.py", line 203, in makedirs
mkdir(name, mode)
OSError: [Errno 17] File exists: 'd:\\temp\\downloads'
I think it is because you are trying to make d:\temp\downloads more than
once. Try os.mkdir('d:/temp/download' + newdir) instead and I suggest you
use forward slashes as separators - it's easier to type and more portable.
Charlie