How to get the extension of a filename from the path

Dale Strickland-Clark dale at riverhall.nospam.co.uk
Thu Dec 8 06:44:52 EST 2005


Lad wrote:

> Hello,
> what is a way to get the the extension of  a filename from the path?
> E.g., on my XP windows the path can be
> C:\Pictures\MyDocs\test.txt
> and I would like to get
> the the extension of  the filename, that is here
> txt
> 
> 
> I would like that to work on Linux also
> Thank you for  help
> L.

Like this, you mean?
>>> import os.path
>>> os.path.splitext("c:\\pictures\\mydocs\\test.txt")
('c:\\pictures\\mydocs\\test', '.txt')

-- 
Dale Strickland-Clark
Riverhall Systems www.riverhall.co.uk





More information about the Python-list mailing list