How can I determine file type without an extension on Windows?

155

64

I sometimes get files from my clients that have the wrong file extension. For example, the name is image.jpg but the file is actually a TIFF image. In many cases I can clarify it by opening the file in a text editor, looking at the first few bytes, then deducing which file type it is.

This works for me with JPEG, TIFF, GIF and PDF files. However there are many more file types out there.

Is it possible to automate identification of the correct file type by analyzing the containing data?

Martin

Posted 2011-04-24T07:36:29.793

Reputation: 3 619

10I do not understand why this question is off-topic (after 3 years). I do not ask for a specific software (i reworded my question to underline this). I just aks for a solution. – Martin – 2014-12-22T10:13:54.123

2I don't understand why 26 people think that boehj *nix-related comment above "adds something useful to the post". This question is tagged windows, but the comment imply: "You can't do that on Windows, you must use *nix instead". So? The comment is directed "for those interested". In what? Change computer? :( – Aacini – 2015-09-08T14:47:04.183

2@Aacini useful for *nix people who come here from google. – jingyu9575 – 2015-11-14T14:46:10.377

@Aacini Also, Windows 10 now supports bash, so file is now a valid answer to this question (although I haven't tested it). – ThatMatthew – 2017-08-15T13:30:02.227

37For those interested the file command does this on *nix machines. – boehj – 2011-04-24T12:37:22.497

Answers

147

You can use the TrID tool which has a growing library of file type definitions for identifying files with.

Screenshot

Wildcards are supported, so in your example you could just put all the images to be examined in a folder, e.g. C:\verifyimages - then you can use the command:

trid C:\verifyimages\*

This will examine all files in the verifyimages folder.


There is also a GUI version available, TrIDNet:

Screenshot

There is documentation available on how you can you can easily integrate TrID or TrIDNet into Windows Explorer and Total Commander:

Windows Explorer

Total Commander

Gaff

Posted 2011-04-24T07:36:29.793

Reputation: 16 863

4Do note that it indicates it is not licensed for commercial use, only personal use – Chris Magnuson – 2015-01-31T17:31:20.333

2I had some trouble figuring out which download files were necessary to use this program. So this comment is to aid in that. You'll need to download two files. First, either the command line utility or the GUI utility. Second, a folder of XML definitions called "TrID XML defs". Place the definition XML files in the same directory as TrID. Then scan definitions. Finally you can start using it. – mrtsherman – 2015-03-26T15:40:12.400

Thanks, mrtsherman, for the clarification. I was confused as well. Docs could be improved, but nice tool! – J Woodchuck – 2018-10-06T17:26:04.013

53

file

File tests each argument in an attempt to classify it. There are three sets of tests, performed in this order: filesystem tests, magic number tests, and language tests. The first test that succeeds causes the file type to be printed.

The type printed will usually contain one of the words text (the file contains only printing characters and a few common control characters and is probably safe to read on an ASCII terminal), executable (the file contains the result of compiling a program in a form understandable to some UNIX kernel or another), or data meaning anything else (data is usually “binary” or non-printable). Exceptions are well-known file formats (core files, tar archives) that are known to contain binary data.

Ignacio Vazquez-Abrams

Posted 2011-04-24T07:36:29.793

Reputation: 100 516

1

The linked to version of file is 5.09 which was released back in [2011] (ftp://ftp.astron.com/pub/file/). To get a much more recent version with an updated libmagic database (5.20 released in 2014 as of this writing) download and install Cygwin.

– Chris Magnuson – 2015-01-31T21:27:28.570

The linked tool doesn't work on Windows 10. – Gqqnbig – 2019-04-16T01:18:46.303

1

@Gqqnbig, that version of file.exe is a decade old and overall status of gnuwin32 is unmaintained since 2013 as per Wikipedia. The modern approach is to use git-for-win: https://git-scm.com/download/win, that bundles Unix utilities (latest versions). After installation, you should have %ProgramFile%\Git\usr\bin in PATH with file.exe in it. For Windows 10 you may also enable Windows Sybsystem for Linux (WSL), install a distro of your choice (ubuntu, fedora, alpine, gentoo, etc.), enter it and do file /mnt/c/your/path/in/windows/filename.extension (/c/ part represents C: drive).

– vulcan raven – 2019-05-25T10:57:29.297

1file is standard, but on older systems (especially non-Linux) not very knowledgeable. For Ubuntu etc it should be quite respectable and even installed as standard. – Thorbjørn Ravn Andersen – 2011-04-24T13:28:24.077

I didn't think file existed on Windows installs at all (don't have a windows box to test with) – Anm – 2011-04-24T18:59:39.820

1

@Anm_LA, it isn't standard at all on Windows, but the link in the answer is to a port of the GNU version of file to Windows. If other *nix commands are interesting to you as a Windows user, then poke around that site to find all kinds of gems.

– RBerteig – 2011-04-24T19:54:14.920

2I very much doubt that file is an expert on files made by Windows applications. – Robin Green – 2011-04-24T20:23:14.673

5@Robin: You're welcome to test it. – Ignacio Vazquez-Abrams – 2011-04-24T20:27:26.527

11@Robin: I very much doubt you've used file at all, and yet you've almost made up your mind about its effectiveness. – tzot – 2011-04-24T23:24:43.137

14

I used to work for the French National Library, to build an digital archive system that contains not only digitized books but also millions of digital artefacts with all kinds of strange file types. We used JHOVE to recognize file formats.

JHOVE is open source, it is maintained by JSTOR and the Harvard University Library. It is rather simple to use.

Nicolas Raoul

Posted 2011-04-24T07:36:29.793

Reputation: 7 766

cool! but does it recognize proprietary formats like TrID does? anyways, I do have some uses to identify subformats/variants of non-proprietary formats (or, to be precise, proprietary 'extensions' to standardized formats), so this would come in handy. thank you for the heads-up! – pepoluan – 2011-04-24T14:00:23.503

1

You can check the file type from any computer including windows at

http://www.checkfiletype.com

John Williams

Posted 2011-04-24T07:36:29.793

Reputation: 11

1

Welcome to Super User! Please read how to recommend software in answers, particularly the bits in bold; then edit your answer to follow the guidelines there. This applies even though you are recommending a website! Cheers

– bertieb – 2018-06-04T11:33:10.790

1

I use Oracle's OutsideIn libraries in my programs. Not free, but they work well, especially for images. The market-speak says it supports over 500 file types.

Richard Brightwell

Posted 2011-04-24T07:36:29.793

Reputation: 149