Is there a way to find out the MIME-TYPE (or is it called "Content-Type"...) of a file in windows batch/PowerShell?
Asked
Active
Viewed 2.5k times
10
-
1http://superuser.com/questions/274734/is-there-a-tool-that-can-determine-the-file-type-from-containing-data – CodeCaster Sep 08 '15 at 14:21
2 Answers
15
While not directly in the Windows command prompt, a more modern approach is to use Git for Windows. Once installed, run git-bash
and the command file path\to\file
. An example output might be:
TestFile.ico: MS Windows icon resource - 1 icon, 128x128, 32 bits/pixel
Alternatively, use the command file -i path\to\file
which might give:
TestFile.ico: image/vnd.microsoft.icon; charset=binary

AlainD
- 5,413
- 6
- 45
- 99
-
Thank you! At least I can get the mime types and construct an `mv` batch to fix the file extensions. Perhaps someone with more time can automate the process :) – ADTC Mar 23 '21 at 17:12
-
Great answer. Didn't have to download anything as I had git installed. – Navjot Singh May 12 '21 at 11:06
7
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.

Paul
- 2,620
- 2
- 17
- 27