permission denied in shutil.copyfile

Steve Holden steve at holdenweb.com
Sat Jul 14 04:05:41 CEST 2007


Gabriel Genellina wrote:
> En Fri, 13 Jul 2007 12:10:20 -0300, Ahmed, Shakir <shahmed at sfwmd.gov>  
> escribió:
> 
>> Is there any way to copy a file from src to dst if the dst is
>> exclusively open by other users.
>>
>> I am using
>>
>> src  = 'c:\mydata\data\*.mdb'
>> dst = 'v:\data\all\*.mdb'
>>
>> shutil.copyfile(src,dst)
>>
>> but getting error message permission denied.
> 
> 1) try with a local copy too, and you'll notice an error too - it's  
> unrelated to other users holding the file open.
> 2) use either r'c:\mydata\data' or 'c:\\mydata\\data\'
> 3) shutil.copyfile copies ONE FILE at a time.
> 4) use glob.glob to find the desired set of files to be copied; and  
> perhaps you'll find copy2 more convenient.
> 
> 
the error is probably due to the unescaped backslash in teh destination 
string - "\a"

 >>> dst = 'v:\data\all\*.mdb'
 >>> dst
'v:\\data\x07ll\\*.mdb'
 >>>

use

dst = r'v:\data\all\*.mdb'

to avoid that problem, and learn how to use raw string literals. I am 
also not sure that you can use wildcards n the destination like you can 
on the Windows command-line copy command, so you may just need to give 
the path to the destination directory.

regards
  Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC/Ltd           http://www.holdenweb.com
Skype: holdenweb      http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------




More information about the Python-list mailing list