Identifying file types in python

Reply

Join Date: Aug 2008
Posts: 2
Reputation: agibbons is an unknown quantity at this point 
Solved Threads: 0
agibbons agibbons is offline Offline
Newbie Poster

Identifying file types in python

 
0
  #1
Aug 17th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 924
Reputation: Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough Gribouillis is a jewel in the rough 
Solved Threads: 216
Gribouillis's Avatar
Gribouillis Gribouillis is online now Online
Posting Shark

Re: Identifying file types in python

 
0
  #2
Aug 17th, 2008
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.
Last edited by Gribouillis; Aug 17th, 2008 at 12:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 2
Reputation: agibbons is an unknown quantity at this point 
Solved Threads: 0
agibbons agibbons is offline Offline
Newbie Poster

Re: Identifying file types in python

 
0
  #3
Aug 17th, 2008
thanks, that helps a lot, I actually looked through the os module, I completely forgot about the os.path module
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 39
Reputation: Shadow14l is an unknown quantity at this point 
Solved Threads: 7
Shadow14l Shadow14l is offline Offline
Light Poster

Re: Identifying file types in python

 
0
  #4
Aug 17th, 2008
  1. filerz = "c:\\cookie\\win\\etc\\beeeeeeepyyrasdf.doom"
  2.  
  3. def filetype(file):
  4. return file.split(".")[-1]
  5.  
  6. print filetype(filerz)
  7.  
  8. >> doom
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 122
Reputation: slate is an unknown quantity at this point 
Solved Threads: 30
slate slate is offline Offline
Junior Poster

Re: Identifying file types in python

 
0
  #5
Aug 18th, 2008
For a more general solution try python-magic.
It is a wrapper for libmagic.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC