[SCRIPT] Identify File Types Using TrID - July 11, 2014

Discuss and share scripts and script files...
Post Reply
Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

[SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by Enternal »

Updated July 11, 2014
* Initial Release.

Allows identification and verification of file types using Marco Pontello's TrID. There are times you run across files that either have not extensions or does not open up correctly perhaps due to wrong extension. Usually you can just open up the file in notepad if it's small enough and hope it's a text type file but other times, it's not possible. With TrID, it can help identify the possible file types.

I made this simply because I download many files and also a lot of images. For some reasons, there are sites where I download images that don't save the extensions correctly. Since there are many files that are either jpg or png, I usually have to rely on IrfanView to tell me if an image file has a wrong header compared to its extension. This saves me a bit more time since it saves a lot of clicks and especially if you are using the custom column script, you can sort by file types which makes it easy to select and batch change the extension.

Setup
Save TrIDNet.icon (icon file) and TrID.xys file into <xyscripts>.
Run this snippet code and then left-mouse-click the button to install the TrID executable:

Code: Select all

Snip: CTB 1
  XYplorer 14.30.0000, 7/11/2014 2:49:41 PM
Action
  NewUserButton
Name
  TrID
Icon
  <xyscripts>\TrIDNet.ico
ScriptL
  Load TrID, "TrID";
ScriptR
  Load TrID, "TrID Update";
FireClick
  0
To run snippet code, type "Snippet;" into address bar. Then paste the code above. The custom toolbar button can be used just like normal. Left click identifies the file and right click update TrID's database.
CTB.png
CTB.png (3.5 KiB) Viewed 4732 times
Now you have two flavors of custom column to use. The first simply takes the result of the file identification and put them into the column from the most likely file type to the least likely file type. Basically "JPG,MP3" means it's most likely a JPG file and while it has characteristics of an MP3 file, it's lower than a JPG. It's always best to actually use the custom toolbar button or the custom column flavor below to get actual percentages of the possible file types since anything after the 1st possible file type could have very low percentages but the script will still display them.
CC.png
CC.png (32.75 KiB) Viewed 4732 times
Alternatively, you can have the custom column with clicking feature. With this, it's a bit easier to test each file by simply clicking the Play button rather than mouse travel all the way to the custom toolbar button and back.
CC Click.png
CC Click.png (31.03 KiB) Viewed 4732 times
Identification Results
TrID.png
TrID.png (43.85 KiB) Viewed 4732 times
Attachments
TrID.zip
July 11, 2014
(3.37 KiB) Downloaded 349 times

pdupreez
Posts: 19
Joined: 15 Aug 2018 11:40

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by pdupreez »

I use TrID a lot (I have a 100tb of data which I try and massage the whole time), and saw this useful script the other day. I ran into a few problems as it is, and not knowing much about programming modern languages (my brain froze after Fortran) I do not know how to fix it properly.

First problem is that with an INSTALLED XYplorer if does not allow me to write into the c:\Program Files (x86) folder unless of course I start XYplorer in admin mode, which I am not sure about.

Second "problem" was because I use TrID, it is already installed and I did not want to setup an additional copy just for XYplorer, so that part of the script I could modify to point to my existing TrID location.

Third "problem" was that the script seems to be geared towards a single file. I like to use it on a directory and its subtrees, and use a PowerShell script I found http://mark0.net/forum/index.php/topic,550.0.html on the website from the author of TrID.

Code: Select all

Foreach ($1 in gci -recurse -name -exclude *.exe, *.doc, *.xyz C:\folders_to_scan\) {$1 = "C:\folders_to_scan\" + $1 ; C:\trid_path\trid.exe $1 -ae}
I have to modify the script each time for the folder it runs against, and/or the files to include or exclude, or not, depending on my needs.

I managed to solve the first problem by moving my XYplorer to a "portable" installation which solved the second one by allowing me to also modify the install location it points towards.

On the third one, I am a bit lost and would appreciate if anyone can assist me to modify the script to:

LeftClick: Run recursively through the current folder without any file inclusion/exclusion (as per the Powershell script)
RightClick: Instead of just updating the definitions to allow me to include a pattern(s) and/or exclude a pattern(s) and then run recursively from the current path, or update TrID definitions.

Thank you

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by highend »

LeftClick: Run recursively through the current folder without any file inclusion/exclusion (as per the Powershell script)
There is quicksearch() which can get you all files including exclusions and recursiveness and the loop... foreach()...
RightClick: Instead of just updating the definitions to allow me to include a pattern(s) and/or exclude a pattern(s) and then run recursively from the current path, or update TrID definitions.
E.g. create entries via a popupmenu() (include pattern, exclude pattern, update trid) and then run whatever you want after checking the value that was selected from the popup menu
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

pdupreez
Posts: 19
Joined: 15 Aug 2018 11:40

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by pdupreez »

highend wrote:
LeftClick: Run recursively through the current folder without any file inclusion/exclusion (as per the Powershell script)
There is quicksearch() which can get you all files including exclusions and recursiveness and the loop... foreach()...
RightClick: Instead of just updating the definitions to allow me to include a pattern(s) and/or exclude a pattern(s) and then run recursively from the current path, or update TrID definitions.
E.g. create entries via a popupmenu() (include pattern, exclude pattern, update trid) and then run whatever you want after checking the value that was selected from the popup menu
Just to confirm, these are XYplorer script commands, and I do not have to use Powershell itself anymore?

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by highend »

Exactly
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

1024mb
Posts: 205
Joined: 14 Dec 2018 23:26

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by 1024mb »

Thanks, I had to add some quotes and now it's working well.
Is there any way to update the def file without Windows asking to confirm the overwrite?

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by highend »

Add the line:

Code: Select all

setting "BackgroundFileOps", 0;
above

Code: Select all

Download "http://mark0.net/download/triddefs.zip", "<xypath>\TrID\", o;
in the
"TrID Update"
part of the script
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

1024mb
Posts: 205
Joined: 14 Dec 2018 23:26

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by 1024mb »

highend wrote: 17 Dec 2018 20:39 Add the line:

Code: Select all

setting "BackgroundFileOps", 0;
above

Code: Select all

Download "http://mark0.net/download/triddefs.zip", "<xypath>\TrID\", o;
in the
"TrID Update"
part of the script
Thank you, it worked. :appl:

dicktatorc
Posts: 9
Joined: 24 May 2023 15:21

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by dicktatorc »

How can i have the two columns named "TrID" and "TrID Click" like in the images above?

highend
Posts: 13033
Joined: 06 Feb 2011 00:33

Re: [SCRIPT] Identify File Types Using TrID - July 11, 2014

Post by highend »

Right click on empty column header, Add Column
Right click that new column header, Select Custom Column...
Double click on an "(Undefined)" entry
Right click that column header again, Configure Custom Column <x>...

Enter the script and look at the rest of the settings...

For the same but with "Click", change the Trigger: to "Click" instead of "Browse"

Code: Select all

$result = runret(lax("<xypath>\TrID\TrID.exe" "<cc_item>"), "%TEMP%", 65001);
    if (strpos($result, "Unknown!") != -1) { return "Unknown"; }
    $types = regexmatches($result, "(\(\.[A-Z0-9/]+?\)|\(\.\)[^(]+)", <crlf>, 1);
    $types = regexreplace($types, "(\(|\)|\.)");
    // Remove duplicates
    $final    = "";
    $existing = "|";
    foreach($type, $types, <crlf>, "e") {
        if (strpos($existing, "|" . $type . "|") == -1) {
            $type      = trim($type);
            $final    .= $type . ",";
            $existing .= $type . "|";
        }
    }
    return trim($final, ",");
cc.png
cc.png (38.08 KiB) Viewed 536 times
One of my scripts helped you out? Please donate via Paypal or paypal_donate (at) stdmail (dot) de

Post Reply