shutil: permission denied errors on windows

John Henry john106henry at hotmail.com
Mon Nov 6 19:23:08 EST 2006


I use the copy function a lot and never have problem.  I suggest that
you write a no brainer standalone test code and if it still fails
there, then you have a problem with your installation.

Antoine De Groote wrote:
> Google tells quite some things about it, but none of them are satisfactory.
>
> I'm on Windows, and shutil operations (e.g. move, copy) throw [Errno 13]
> Permission denied all the time, for the source files. It seems that this
> is the case for all my files. But what I don't understand is that
> yesterday it still worked. I didn't change anything on my system though
> (at least not that I am aware of). I restarted the computer several
> times to see if that helped, but it didn't. Also I can't find a process
> that would be using the files...
>
> Has anybody experienced this problem before, or have a solution?
>
> Kind regards,
> antoine
>
> Here's the code that throws the errors
>
> [...]
> for l in files:
>              from_file = os.path.join(dir, l)
>              to_file = from_file.replace(tree_top, backup_dir)
>              try:
>                  if not os.path.exists(to_file):
>                      log('Copying new      %s' % from_file)
>                      counter_new += 1
>                      shutil.copy2(from_file, to_file)
>                  elif int(os.path.getmtime(from_file)) >
> int(os.path.getmtime(to_file)):
>                      log('Copying modified %s' % from_file)
>                      counter_mod += 1
>                      shutil.copy2(from_file, to_file)
>                  elif os.path.getsize(from_file) > os.path.getsize(to_file):
>                      log('Sizes differ, but not rest: Copying %s' %
> from_file)
>                      counter_special += 1
>                      shutil.copy2(from_file, to_file)
>                  elif os.path.getsize(from_file) < os.path.getsize(to_file):
>                      log('Orig file smaller than backup file: Copying
> %s' % from_file)
>                      counter_special += 1
>                      shutil.copy2(to_file, backup_dir+'DIFF_SIZE')
>                      shutil.copy2(from_file, to_file)
>                  else:
>                      #log('not treated: %s' % l)
>                      pass
>
>              except (OSError, IOError), e:
>                  not_accessible += 1
>                  print e
> [...]




More information about the Python-list mailing list