shutil: permission denied errors on windows

Discussion in 'Python' started by Antoine De Groote, Nov 6, 2006.

  1. 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
    [...]
     
    Antoine De Groote, Nov 6, 2006
    #1
    1. Advertising

  2. Antoine De Groote

    John Henry Guest

    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
    > [...]
     
    John Henry, Nov 7, 2006
    #2
    1. Advertising

  3. Yes it's strange, I never had the problem before, either. It seems now
    to be only the case for folders. A very simple

    shutil.copy('a', 'b')

    already fails with the error message.

    I reinstalled Python, but that didn't change anything...

    Regards,
    antoine

    John Henry wrote:
    > 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
    >> [...]

    >
     
    Antoine De Groote, Nov 7, 2006
    #3
  4. Antoine De Groote

    Guest

    Antoine De Groote schrieb:

    > Yes it's strange, I never had the problem before, either. It seems now
    > to be only the case for folders. A very simple
    >
    > shutil.copy('a', 'b')
    >
    > already fails with the error message.
    >
    > I reinstalled Python, but that didn't change anything...
    >
    > Regards,
    > antoine
    >


    Just a guess, update you virus scanner. Maybe someone sits in the back
    and doesn't like what you are doing.

    Regards Jürgen
     
    , Nov 7, 2006
    #4
  5. Antoine De Groote

    John Henry Guest

    Okay, it's always good that strange things are repeatable and happens
    with simple scripts.

    Are you saying "a" is a folder? So, the failure is only with copying
    folder? Not individual file?



    Antoine De Groote wrote:
    > Yes it's strange, I never had the problem before, either. It seems now
    > to be only the case for folders. A very simple
    >
    > shutil.copy('a', 'b')
    >
    > already fails with the error message.
    >
    > I reinstalled Python, but that didn't change anything...
    >
    > Regards,
    > antoine
    >
    > John Henry wrote:
    > > 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
    > >> [...]

    > >
     
    John Henry, Nov 7, 2006
    #5
  6. Yes, that's exactly what was the case... But see my other post, that
    straightens things up...

    Thanks!
    antoine


    John Henry wrote:
    > Okay, it's always good that strange things are repeatable and happens
    > with simple scripts.
    >
    > Are you saying "a" is a folder? So, the failure is only with copying
    > folder? Not individual file?
    >
    >
    >
    > Antoine De Groote wrote:
    >> Yes it's strange, I never had the problem before, either. It seems now
    >> to be only the case for folders. A very simple
    >>
    >> shutil.copy('a', 'b')
    >>
    >> already fails with the error message.
    >>
    >> I reinstalled Python, but that didn't change anything...
    >>
    >> Regards,
    >> antoine
    >>
    >> John Henry wrote:
    >>> 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
    >>>> [...]

    >
     
    Antoine De Groote, Nov 7, 2006
    #6
  7. Thanks for your replies, guys. I found the problem now.

    Actually the problem arised just before the code that I had in my
    original post.

    Here are the 2 lines that mess things up. It's those that are commented
    out. If not commented, the errors were raised.

    Clearly there is an error in the second line. It includes subdirs and s
    instead of files and f. Took me 2 days to finally see it.

    for dir, subdirs, files in os.walk(tree_top):

    # subdirs[:] = [s for s in subdirs if
    os.path.join(dir,s).replace('\\', '/') not in excluded]
    # files[:] = [f for f in subdirs if
    os.path.join(dir,s).replace('\\', '/') not in excluded]

    for s in subdirs:
    bak_sub = os.path.join(dir, s).replace(tree_top, backup_dir)
    if not os.path.exists(bak_sub):
    log('Creating directory %s' % bak_sub)
    os.mkdir(bak_sub)

    for l in files:
    [code pasted earlier]...



    But what still beats me is why my minimal example with folders 'a' and
    'b' didn't work... It was independent of this code...

    Anyway, my program works now, and that's for the moment the most
    important thing.

    Regards,
    antoine

    John Henry wrote:
    > 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
    >> [...]

    >
     
    Antoine De Groote, Nov 7, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan
    Replies:
    1
    Views:
    4,790
    Frances Valdes
    May 5, 2004
  2. Stéphane Ninin

    shutil.move, permission denied, why ?

    Stéphane Ninin, Apr 6, 2004, in forum: Python
    Replies:
    8
    Views:
    1,403
    Stéphane Ninin
    Apr 8, 2004
  3. Russell Warren
    Replies:
    4
    Views:
    707
    Russell Warren
    Jul 27, 2006
  4. Ahmed, Shakir

    permission denied in shutil.copyfile

    Ahmed, Shakir, Jul 13, 2007, in forum: Python
    Replies:
    0
    Views:
    611
    Ahmed, Shakir
    Jul 13, 2007
  5. Fletcher Johnson

    Why is the shutil module called shutil?

    Fletcher Johnson, Sep 24, 2011, in forum: Python
    Replies:
    11
    Views:
    910
    alex23
    Sep 26, 2011
Loading...

Share This Page