471,055 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,055 software developers and data experts.

get Windows file type

Using Python on Windows XP, I am able to get almost all file and path
info using os.path or stat, but I don't see a way to retrieve the file
type? E.g. Microsoft Word file, HTML file, etc, the equivalent of what
is listed in the "Type" column in the Windows Explorer box.

Thanks,

rick

May 8 '06 #1
3 1599
BartlebyScrivener enlightened us with:
Using Python on Windows XP, I am able to get almost all file and
path info using os.path or stat, but I don't see a way to retrieve
the file type? E.g. Microsoft Word file, HTML file, etc, the
equivalent of what is listed in the "Type" column in the Windows
Explorer box.


I'm afraid you'll have to get that from the registry. That will only
give you the descriptive name of the extension, though, and not the
type of contents of the file, i.e. if you have a HTML file named
'somefile.avi', Windows recognises it as an AVI and not an HTML file.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
May 8 '06 #2
BartlebyScrivener wrote:
Using Python on Windows XP, I am able to get almost all file and path
info using os.path or stat, but I don't see a way to retrieve the file
type? E.g. Microsoft Word file, HTML file, etc, the equivalent of what
is listed in the "Type" column in the Windows Explorer box.

Thanks,

rick

This worked well for me on Linux, should work on Windows:

http://www.demonseed.net/~jp/code/magic.py

-Don
May 8 '06 #3
If you have pywin32 installed, you can use the shell module.

from win32com.shell import shell, shellcon
shell.SHGetFileInfo(filename ,0, shellcon.SHGFI_TYPENAME)

Roger

"BartlebyScrivener" <rp*******@gmail.com> wrote in message news:11**********************@u72g2000cwu.googlegr oups.com...
Using Python on Windows XP, I am able to get almost all file and path
info using os.path or stat, but I don't see a way to retrieve the file
type? E.g. Microsoft Word file, HTML file, etc, the equivalent of what
is listed in the "Type" column in the Windows Explorer box.

Thanks,

rick


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
May 10 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Paul Rubin | last post: by
4 posts views Thread by tshad | last post: by
6 posts views Thread by ulillillia | last post: by
6 posts views Thread by Chris Marsh | last post: by
2 posts views Thread by =?Utf-8?B?SnJ4dHVzZXIx?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.