detect if file or dir

Bill Bell bill-bell at
Thu Jul 12 02:37:27 CEST 2001

pedro at (pedro) wrote:
> how can i detect if sth. is a file or a directory? exists(directory)
> does tell me if sth. is a directory but exits my script wenn it hits a
> file.


I assume you mean that the use of 'exists' raises an exception?

Notwithstanding the comments offered by others on this list, I don't 
think it should. For example, on my machine:

>>> os.path.exists ( r'c:\temp.txt')

ie, it works without raising an exception given a file name.


More information about the Python-list mailing list