473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1684
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Paul Rubin | last post by:
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows...
2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
3
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim...
3
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
4
by: tshad | last post by:
What would be a good way to check programmatically whether a service was running? We have a service that dies periodically and I need to check to see if this service is running. I know how to...
6
by: ulillillia | last post by:
I've been following the tutorial here to learn Windows programming (along with the help file from the Windows Platform SDK): http://www.cprogramming.com/tutorial/opengl_windows_programming.html ...
6
by: Chris Marsh | last post by:
All I have a database table, changes to the data within which I am interested in acting on. The approach that I'm taking is to have the database update a file every time data is updated. This...
2
by: =?Utf-8?B?SnJ4dHVzZXIx?= | last post by:
I just started using Windows Live OneCare, I had been using Norton, but was unable to fix the problems I was having. I have yet been unsuccessful with OneCare as well. I keep getting the same...
3
by: shobhitguptait | last post by:
How to Run C#.NET Windows App on N/W with centralized DB using SQL SERVER 2000 Hello All...i m really grate full to c such a website where developers try to help people like us who face problems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.