I have a directory full of randomly named files of different types, all with no file extensions. Most are images, with some videos, and some plaintext. I've used one of the Windows versions of file to confirm the files can all be identified by their headers/metadata, but would like to automate the naming as there are roughly 2400 files.

I don't care so much about the filename as much as just having the appropriate extension for it's type. Is anyone aware of a program or script that can do this?


This seems to be similar to this question except that you require the files to be renamed in addition to simply identifying them. This can also be done with the same tool (TrID - File Identifier) that is mentioned in that question.

TrID is an utility designed to identify file types from their binary signatures. While there are similar utilities with hard coded logic, TrID has no fixed rules. Instead, it's extensible and can be trained to recognize new formats in a fast and automatic way. The definitions file (also downloadable from the same website) currently as 5000+ filetypes.

You can use command TrID on the command line with the -ae switch to instruct TrID to rename the files after identification. For example:

C:\TrID>trid c:\temp\* -ae


TrID/32 - File Identifier v2.20 - (C) 2003-15 By M.Pontello
Definitions found: 5702 Analyzing...

File: c:\temp\FILE0001.CHK 75.8% (.BAV) The Bat! Antivirus plugin (187530/5/21)

File: c:\temp\FILE0002.CHK 77.8% (.OGG) OGG Vorbis Audio (14014/3)

File: c:\temp\FILE0003.CHK 86.0% (.DOC) Microsoft Word document (49500/1/4)

File: c:\temp\FILE0004.CHK 42.6% (.EXE) UPX compressed Win32 Executable (30569/9/7)

4 file(s) renamed.

| improve this answer | |
  • Just revisited this question and this answer is exactly what I was looking for when originally posted, thank you. – Infraded Jun 25 '15 at 20:00

I've been told that this http://www.rlvision.com/flashren/about.asp works. Though I've never been in a place to test.

If it seems to be a dud, http://gnuwin32.sourceforge.net/packages/file.htm has the linux file() command rewritten for use in a windows environment. then run a nice batch like this:

@echo off
dir /b "c:\(path to folder containing files)" >>files.txt
for /f %%i in (files.txt) do (
##use file /b and a set of conditionals with find to parse extensions  
based on header) del filelist.txt

Good Luck!

| improve this answer | |

Under windows, there is filetype.exe and does exactly what you need. You can download it from here: http://home.fnal.gov/~jklemenc/filetype.html. It also contains a mini help.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.