I am making my own file manager for linux, hopefully it will be cross platform, and I am trying to identify different file types, in particular folders.

I have already searched google but I could only find a way of identifying text files.
Does anyone have any advice on identifying file types?

Recommended Answers

All 4 Replies

folders are easy to identify, use the function os.path.isdir() .
look if functions in os.path suffice to your needs :)
Also for common path operations, there is a nice Path class which exists at python.org. It was rejected as a standard class in python, but it can be useful. Look here http://www.python.org/dev/peps/pep-0355/. It's impelmented here http://wiki.python.org/moin/PathModule.

thanks, that helps a lot, I actually looked through the os module, I completely forgot about the os.path module

filerz = "c:\\cookie\\win\\etc\\beeeeeeepyyrasdf.doom"

def filetype(file):
    return file.split(".")[-1]

print filetype(filerz)

>> doom

For a more general solution try python-magic.
It is a wrapper for libmagic.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.