Alex Rivera | Logout

os.path.exists() for files in your Path?

Asked 2009-04-22T01:09:31.657
16

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.

Edit
Report

1 Answer

0

On Unix you have to split the PATH var.

if any([os.path.exists(os.path.join(p,progname)) for p in os.environ["PATH"].split(":")]):
    do_something()
answered 2009-04-22T12:37:50.673

Your Answer