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 879161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:53:11+00:00 2026-05-15T11:53:11+00:00

Well, I have made a module that allows you to copy a file to

  • 0

Well, I have made a module that allows you to copy a file to a directory easier. Now, I also have some “try’s” and “except’s” in there to make sure it doesn’t fail in the big messy way and doesn’t close the terminal, but I also want it to display different error messages when a wrong string or variable is put in, and end the module, but not the…if I may say, Terminal running it, so I did this:

def copy():
    import shutil
    import os
    try:
        cpy = input("CMD>>> Name of file(with extension): ")
        open(cpy, "r")
    except:
        print("ERROR>>> 02x00 No such file")
    try:
        dri = input("CMD>>> Name of Directory: ")
        os.chdir(dri)
        os.chdir("..")
    except:
        print("ERROR>>> 03x00 No such directory")
    try:
        shutil.copy(cpy, dri)
    except:
        print("ERROR>>> 04x00 Command Failure")

Problem is that it doesn’t end the module if there is no file or directory, only at the finish.

  • 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-05-15T11:53:12+00:00Added an answer on May 15, 2026 at 11:53 am

    You may be thinking that when an exception is raised, Python just stops what it’s doing, but that’s not quite true. The except: block actually catches the exception raised, and is supposed to handle it. After an except: block finishes, Python will continue on executing the rest of the code in the file.

    In your case, I’d put a return after each print(...). That way, after Python prints out an error message, it will also return from the copy() function rather than continuing to ask for more input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made one project in java. Now in this particular module, i am
I have made an SQLite database file with some testdata in it. When I
I have made an application that copy the vb components to the system32 folder
Well I have this MySQL stored procedure that I wrote and if I run
Well basically I have this script that takes a long time to execute and
I have this RewriteRule that works too well :-) RewriteRule ^([^/]*)/$ /script.html?id=$1 [L] The
I have an application that works pretty well in Ubuntu, Windows and the Xandros
I have made a web app where I am using a module which redirects
Good evening everyone! I am working on learning some java and I have made
Well I have made a custom Android UI, and I need my UI view

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.