seperating directories from files

John Zenger john_zenger at yahoo.com
Mon Jan 30 09:54:00 EST 2006


raj wrote:
> How can I find ... if it's a file,
> whether it is an image file or not?

Assuming you are running on an operating system that uses file 
extensions to indicate a file is an image (like Windows or Linux), 
something like this will work:

import os.path

def isImage(filename):
     return os.path.splitext(filename)[1] in ['.jpg','.png','.gif']

(Add as many file extensions to that list as you like...)

> Is there any method to read the metadata of files?

It's not what you are looking for here, but os.stat gives you access to 
lots of information about files.  In Linux and Windows, though, the 
'type' of a file is incorporated into its filename through an extension.



More information about the Python-list mailing list