get Windows file type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BartlebyScrivener

    #1

    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

  • Sybren Stuvel

    #2
    Re: get Windows file type

    BartlebyScriven er enlightened us with:[color=blue]
    > 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.[/color]

    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

    Comment

    • dwelch

      #3
      Re: get Windows file type

      BartlebyScriven er wrote:[color=blue]
      > 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
      >[/color]
      This worked well for me on Linux, should work on Windows:



      -Don

      Comment

      • Roger Upole

        #4
        Re: get Windows file type

        If you have pywin32 installed, you can use the shell module.

        from win32com.shell import shell, shellcon
        shell.SHGetFile Info(filename ,0, shellcon.SHGFI_ TYPENAME)

        Roger

        "BartlebyScrive ner" <rpdooling@gmai l.com> wrote in message news:1147089470 .336984.173510@ u72g2000cwu.goo glegroups.com.. .[color=blue]
        > 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
        >[/color]



        ----== 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 =----

        Comment

        Working...