how do i check if a file exists with python?

David C. Ullrich ullrich at
Thu Dec 28 14:57:31 EST 2000

In article <RlM26.98766$yR4.2639444 at>,
  "Scott Hathaway" <slhath at> wrote:
> I have searched Deja, looked in two pyton books, and searched the
> site trying to find out this simple question.

Have you tried the _documentation_?

> Can someone please give me the call and the module it lives in?

I don't recall what it is exactly...[five minutes later]:

One way is with glob:

import glob

def FileExists(filename):
	return len(glob.glob(filename)) > 0

if FileExists(r'c:/windows/notepad.exe'):
	print 'yup'
if not FileExists(r'c:/windows/notepad.exk'):
	print "I didn't think so."

May or may not be the Right way.

> Thanks,
> Scott

Oh, dejanews lets you add a sig - that's useful...

Sent via

More information about the Python-list mailing list