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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:06:40+00:00 2026-05-11T14:06:40+00:00

I commonly use os.path.exists() to check if a file is there before doing anything

  • 0

I commonly use os.path.exists() to check if a file is there before doing anything with it.

I’ve run across a situation where I’m calling a executable that’s in the configured env path, so it can be called without specifying the abspath.

Is there something that can be done to check if the file exists before calling it? (I may fall back on try/except, but first I’m looking for a replacement for os.path.exists())

btw – I’m doing this on windows.

  • 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. 2026-05-11T14:06:41+00:00Added an answer on May 11, 2026 at 2:06 pm

    You could get the PATH environment variable, and try ‘exists()’ for the .exe in each dir in the path. But that could perform horribly.

    example for finding notepad.exe:

    import os for p in os.environ['PATH'].split(os.pathsep):     print os.path.exists(os.path.join(p, 'notepad.exe')) 

    more clever example:

    if not any([os.path.exists(os.path.join(p, executable) for p in os.environ['PATH'].split(os.pathsep)]):     print 'can't find %s' % executable 

    Is there a specific reason you want to avoid exception? (besides dogma?)

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

Sidebar

Related Questions

Is there a easy to use (from .net) and commonly accepted file format for
I commonly run into the following situation where I have a data structure which
When writing programs (C#.NET) I'll commonly use external libraries I've downloaded from various websites
Are there any commonly used patterns in Javascript for storing the URL's of endpoints
I have seen two commonly used techniques for adding the directory of the file
When building websites I commonly use tools such as Browsershots to ensure that my
Is there a list describing all of the data_type parameters you can use in
Which one of these two is most commonly used scenario? I want to use
What techniques do people commonly use for uploading, storing and presenting images with a
there is a quote from Algorithms for Java (sedgwick 2003) p. 135: we commonly

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.