How to batch rename files based on file header/metadata in Windows?

6,757

Solution 1

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

Output:

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.

Solution 2

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!

Share:
6,757

Related videos on Youtube

Infraded
Author by

Infraded

Updated on September 18, 2022

Comments

  • Infraded
    Infraded over 1 year

    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?

  • Infraded
    Infraded almost 9 years
    Just revisited this question and this answer is exactly what I was looking for when originally posted, thank you.