A simple way to test a existence of a file


(Manuel) #1

What’s the most quick and simple way to test
a existence of a file? I don’t want open it, only test.

Thanks,

     Manuel

(theeth) #2

import os
Filename = "Blah.txt"
Path = "c:/temp/"
if Filename in os.listdir(Path):
        print "The file is there"
else:
        print "The file is not there"

Martin


(eeshlo) #3

It can be done simpler, there is a specific function for this:


if os.path.exists(filename): ...


(Manuel) #4

perfect!!! :smiley:
thanks!!