get Windows file type

  • Thread starter BartlebyScrivener
  • Start date
B

BartlebyScrivener

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
 
S

Sybren Stuvel

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
 
D

dwelch

BartlebyScrivener said:
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
 
R

Roger Upole

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,213
Latest member
DonnellTol

Latest Threads

Top