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

  • SEARCH
  • Home
  • 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 8173025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:59:08+00:00 2026-06-06T21:59:08+00:00

I’m a beginner python programmer using it for simple admin tasks. I have written

  • 0

I’m a beginner python programmer using it for simple admin tasks.

I have written a small log moving code (as I have a system that generates alot of log files that get moved from the server to storage).

I am getting a permissions error on a file on the remote path has permission denied when trying to copy so have wrapped this in a try: statement to try and by pass the error but the script is still ending… line 32 is shutil.copy2 (location,copylocation).

Base path is a local directory and log dir is a UNC path (which is appended with the folder set). Folders are mirrored across both file systems earlier in the script. (so should always exist).

Other try’s such as around the os.remove work OK.

If anyone could point me in the general direction would be appreciated.

Traceback (most recent call last):
  File "C:\Program Files (x86)\Log Mover\log_mover.py", line 32,
  shutil.copy2 (location,copylocation)
  File "C:\Python27\lib\shutil.py", line 127, in copy2
  copyfile(src, dst)
  File "C:\Python27\lib\shutil.py", line 82, in copyfile
    with open(dst, 'wb') as fdst:
  IOError: [Errno 13] Permission denied: '\\\\XXXX\\d$\\logs\\
  logs/XXX\\XXX - 2012-07-03 21-49.XXXX'
  ☀could not delete:C:/logs/XX\XXX\XXX 2012-07-04 08-00-42.txt
  Traceback (most recent call last):


for root, dirs, files in os.walk(basepath):
   for filenames in files:
        location = os.path.join(root, filenames)
        try:
            datemod = time.strftime("%Y%m%d%H",time.localtime(os.path.getmtime(location)))
        except OSError:
            print "count not get mod time:"+location
        if datemod != currtime:
            drive,path = os.path.splitdrive(location)
            copylocation = str(logdir)+str(path)
            try:
                shutil.copy2 (location,copylocation)
            except OSError:
                print "could not copy"
            pass

            if os.path.getsize(location) == os.path.getsize(copylocation):
                try:
                    os.remove(location)
                    print "Deleted"+location
                except OSError:
                    print "could not delete:"+location
                pass
            else:
                print "sizes dont match"

Thanks

Kenny

  • 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-06T21:59:09+00:00Added an answer on June 6, 2026 at 9:59 pm

    You’re trying to catch OSError, while you get IOError.

    Add this:

    except (OSError, IOError):
        #some code
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.