Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:57:06+00:00 2026-06-03T09:57:06+00:00

Consider the following directory tree Work—>subdir1—>File1 | | | —->File2 | –>subdir2—>File3 There exists

  • 0

Consider the following directory tree

Work--->subdir1--->File1
    |         |
    |         ---->File2
    |
    -->subdir2--->File3

There exists another similar directory tree

Gold--->subdir1--->File1
    |         |
    |         ---->File2
    |
    -->subdir2--->File3

I have to write a script to copy the Work directory to another location. I have been using shutil.copytree for the same.

The problem is, at times (but not always) I may not have permission to access some files, say, File2 in the Work directory, and will get the following error:

Traceback (most recent call last):
File "C:\Script.py", line 81, in <module>
shutil.copytree(source_loc,dest_loc)
File "C:\Python32\lib\shutil.py", line 239, in copytree
   raise Error(errors)
   shutil.Error: [('C:\\Work\\subdir1\\File2', 
   'C:\\Dest\\subdir1\\File2', 
"[Errno 13] Permission denied: 'C:\\Work\\subdir1\\File2'")]

In such situations, I will have to copy those corresponding files from the Gold directory.
Is there a way in which I can automate the copying of the corresponding files from Gold directory through an exception? Say something like:

try:
   shutil.copytree(r'C:\Work',r'C:\Dest')
except:
   << Copy Inaccessible Files from Gold >>

I was initially thinking about using os.walk, to copy files individually. This way whenever I encounter an exception for a particular file, I will be able to copy that corresponding file from Gold. Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:57:12+00:00Added an answer on June 3, 2026 at 9:57 am

    You can get the list of files that failed to copy from shutil.Error. From reading the source, shutil.Error contains (src, dst, why) triplets. You can do something like:

    try:
        shutil.copytree(srcdir, dstdir)
    except shutil.Error, exc:
        errors = exc.args[0]
        for error in errors:
            src, dst, msg = error
            # Get the path to the file in Gold dir here from src
            shutil.copy2(goldsrc, dst)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following directory structure: ROOT ------ images ............... logo.png ------ includes ............... vars.php
Consider the following subversion directory structure /dir1/file.txt /dir2/file.txt I want to move the file.txt
Consider the following directory structure: ./source/com/mypackage/../A.java ./extensions/extension1/source/com/mypackage/../T.java ./extensions/extension2/source/com/mypackage/../U.java ... ./extensions/extensionN/source/com/mypackage/../Z.java I want to produce
Consider the following Bash command lines: time ls # Sends directory contents to stdout
Consider a directory structure containing the following files: \1.3\Baseline\GeneratedScripts\One\FullInstall.cmd \1.3\Baseline\GeneratedScripts\Two\FullInstall.cmd \1.3\Baseline\GeneratedScripts\Three\FullInstall.cmd \1.3\Patches\Patch1\GeneratedScripts\One\FullInstall.cmd \1.3\Patches\Patch1\GeneratedScripts\Two\FullInstall.cmd \1.3\Patches\Patch1\GeneratedScripts\Three\FullInstall.cmd
Consider the following: try { FileStream fileStream = new FileStream(C:\files\file1.txt, FileMode.Append); } catch (DirectoryNotFoundException
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider following program: static void Main (string[] args) { int i; uint ui; i
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.