On 27/03/2012 05:00, Michael Lewis wrote:
Traceback (most recent call last): File "C:\Python27\Utilities\copyfiles.py", line 47, in <module> copyfiles(srcdir, dstdir) File "C:\Python27\Utilities\copyfiles.py", line 42, in copyfiles shutil.copy(srcfile, dstfile) 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\\Chief Ninja\\Pictures\\testdir'
It's not 100% clear what's going on, but it looks as though you've passed along paths whicih result in shutil trying to open a *directory* for reading -- which it won't be able to do. (It is, in fact, possible to get a file handle to a directory on Windows but you don't want to do that and shutil doesn't know how).
I've noticed that the code runs if I use shutil.copyfiles instead of shutil.copy. Do you know why?
Assuming my premise above, it would be because it special-cases directories passed as parameter. (I haven't actually looked at the code to check). With this kind of problem the most helpful thing you can do for yourself -- and for us if you can't resolve it yourself -- is to pull yourself out of the depths of your copy/copyfiles architecture and to try to do a simple: open ("c:/path/to/file.txt", "rb") If that succeeds then obviuosly there's no permissions issue as such. If it fails (with an access error) then we're onto something. If it succeeds then, probably your more complex copyfiles code is doing something you don't think it's doing. Start chucking out print () statements or logging or something so you know *exactly* where the paths are pointing to which you're passing into the shutil or other stdlib functions. Hopefully all this will make it clearer what's going on. Full marks for posting your code -- that does help. But you'll do better if you post a *minimal* code example, and preferably a self-complete one. TJG _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor