how do i check if a file exists with python?

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


In article <RlM26.98766$yR4.2639444 at news1.rdc1.tx.home.com>,
  "Scott Hathaway" <slhath at DownWithSpam.home.com> wrote:
> I have searched Deja, looked in two pyton books, and searched the
python.org
> 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 Deja.com
http://www.deja.com/



More information about the Python-list mailing list