Is there any way to make Windows smart about different file types with same extension?

1

The problem is for .ts files which currently Windows identifies them as video format.

I want .ts files that are videos open with video player and .ts files that are TypeScript open with code editor.

Any solution?

Sina

Posted 2018-09-15T16:41:48.797

Reputation: 11

You would have to write a helper app that is able to distinguish the two different kinds of files and launch the appropriate application. That is off-topic for [su] – DavidPostill – 2018-09-15T16:47:36.923

Visual Studio has something like that – Ramhound – 2018-09-15T16:50:00.077

Maybe detect file content. I'd guess typescript is only text, where as the video format is likely different (binary? ) – Dave – 2018-09-15T20:24:12.150

Answers

2

A very simple-minded idea is to distinguish between the two cases by the size of the file being launched, since video files are much larger.

You can create a program to intercept in Explorer the double-click on .ts files that will launch either the player or an editor. This can done even by just a .bat file that has the file as its parameter.

An (untested) model for such a .bat file is :

@echo off
setlocal
set maxbytesize=10000

FOR /F "usebackq" %%A IN ('%1') DO set size=%%~zA

if %size% LSS %maxbytesize% (
    editor.exe '%1'
) else (
    player.exe '%1'
)

You would need to designate this script as handler for .ts files. See for that this StackOverflow answer.

If you wish to avoid the black rectangle in which the .bat script will execute, see the post
Run a batch file in a completely hidden way.

harrymc

Posted 2018-09-15T16:41:48.797

Reputation: 306 093

Another way to do this would be to make your script call TrID (http://mark0.net/soft-trid-e.html) with the name of the file and then launch the appropriate program depending on what filetype it returned.

– Richard – 2018-09-15T22:50:27.623