Search code examples
windowsbatch-filecontent-type

How can I find out a files “mime-type(Content-Type?)”? on Windows


Is there a way to find out the MIME-TYPE (or is it called "Content-Type"...) of a file in windows batch/PowerShell?


Solution

  • Use File from source or you can get win32 binaries from here

    Example from empty file:

    COPY NUL >test.ext && "C:\Program Files (x86)\GnuWin32\bin\file" −-mime-type test.ext
    

    Which will return this:

    test.ext; text/plain
    

    Update:

    Also -b or --brief do not prepend filenames to output lines

    file -b −-mime-type test.ext return only the mime-type: text/plain

    Type file --help for more options

    Note: The sources are much more recent than the executable file kindly made available to us by GnuWin32.