Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Multiple programs use the same file extension, but the formats are totally different and incompatible. For instance, I have .sch files on my computer that are in at least 5 different formats (TINA, PSpice, PADS, Protel, and Eagle). Is there a way to get Windows to treat them differently, so that double-clicking on such a file opens it in the program it's meant to be opened in?

Linux uses magic numbers in the files themselves to differentiate, and only uses file extensions as a fallback plan. (All PNG files start with the bytes 89 50 4E 47 0D 0A 1A 0A, for instance, regardless of what you name them.) It would be nice if Windows could support this, but probably very difficult to implement. Maybe something simpler like a second-level extension, like filename.program1.sch and filename.program2.sch? Maybe some kind of filter that renames files on the fly?

Better idea: Associating the ambiguous extension with a pre-processor (.bat file or dedicated app) that checks for a second-level extension or goes into the file itself and scans for the magic number and then launches the appropriate program?

share|improve this question
TrID may be of interest to you -- it has a database of 4400 binary signatures. – josh3736 Aug 2 '11 at 14:28
I remember this used to happen on the RISC OS but sometimes used to cause frustration when you had multiple apps that could process the same file type and it would open the program with the wrong program! – Matt Wilko Aug 2 '11 at 14:58
@Matt: Great, thanks! – endolith Aug 3 '11 at 4:03

Windows does not launch files based on any information in the file - building a database for that would take an incredible amount of work and programming. The only true way to identify a file is by the binary signatures in the file, if the file even has it, and this is up to the software author to implement.

In Windows, files are passed to the program you specify for a particular file extension. Windows determines a file's extension as the substring which follows the last occurrence of a period, so it's not possible with the file names you posted.

You have to either re-name the files (and give them unique file extensions), or write a batch file to launch the appropriate application for you. For more details, see this Technet article.

share|improve this answer
I was trying to make this work by creating a unique file extension, but even if he did, the real problem is that most programs will only recognize their own extensions despite content, and would not open them anyway. – KCotreau Aug 2 '11 at 1:33
I would love to see someone do this, though. I think the way you would get around it is to have a single program open files of all extensions, and have that program keep its own database (using NTFS's alternate streams to keep track of files) and launch each respective program that the user defines for each file. It wouldn't be that much work, but I can see a lot of problems with this approach, so that's probably why no one has done it. – Sasha Chedygov Aug 2 '11 at 1:35
it wouldn't be TOO hard - there's tools that do it (trid, or file) and most posix based oses look at file headers, and not extensions. Its less a matter of design choices, than the amount of effort it would take. Naturally this would be a lot harder for a third party, but if MS felt it was needed, this might be semi-trivial – Journeyman Geek Aug 2 '11 at 1:57
"Using NTFS's alternate streams to keep track of files." It's obvious to me why Windows doesn't implement the Linux/POSIX model. Simply that it requires a file read. If that was the case, everytime you right clicked a file, it has to fire off an expensive file read. Even worse, imagine if it was a network file and the connection had a noticable lag. People would just blame WinDoze. Raymond Chen would bash on this technique also cause it would cause a file to be recalled if it was on a tertiary storage area. – surfasb Aug 2 '11 at 5:30
But Windows does allow you to break that model. . . – surfasb Aug 2 '11 at 5:30
up vote 7 down vote accepted

I solved it myself:

I made a Python script that reads the first few bytes of a file and compares them to a dictionary, then launches the appropriate program based on the magic numbers.

import sys
import subprocess

magic_numbers = {
'OB': r'C:\Program Files (x86)\DesignSoft\Tina 9 - TI\TINA.EXE', # TINA
'*v': r'C:\Program Files (x86)\Orcad\Capture\Capture.exe', #PSpice
'DP': r'C:\Program Files (x86)\Design Explorer 99 SE\Client99SE.exe', #Protel
'\x00\xFE': r'C:\MentorGraphics\9.0PADS\SDD_HOME\Programs\powerlogic.exe', #PADS Logic
'\x10\x80': r'C:\Program Files (x86)\EAGLE-5.11.0\bin\eagle.exe', # Eagle

filename = sys.argv[1]
f = open(filename, 'rb')
# Read just enough bytes to match the keys
magic_n =[magic_numbers[magic_n], filename])

Latest version will be here: Launch ambiguous files in the appropriate program

I tried to associate the file extension with this script, but Windows 7 didn't let me. It just associated it with Python instead, so I went into the registry and added the script name manually.

How to associate a file extension with a Python script

Room for improvement, but it works. I can double-click on different files with the same .sch extension and they open in different apps.

Update: I've converted it to an .exe using cx_freeze, with an external YAML config file, and it's easy to associate. See also this libmagic proposal. Not sure if I should make this into a full-fledged "libmagic launcher for Windows" or if it's better to handle only one file extension with one .exe and a simple YAML file.

share|improve this answer
This would actually be trivial to write as an exe. . . – surfasb Aug 2 '11 at 5:31
Not if you don't know how to write exes :) – endolith Aug 2 '11 at 14:26
It wasn't a knock on ya. It was something for myself :) – surfasb Aug 2 '11 at 16:22
@surasb: So have you written me an .exe yet? It's trivial, right? :) – endolith Aug 17 '11 at 14:21
I totally forgot! I've been messing with 3D meshes on Silverlight for the past week. Later tonight, after I babysit this RAID array. . . – surfasb Aug 17 '11 at 16:28

To start, you can rename one of the types of files to have a new extension, and use the "open with" dialogue to set a default program to open those types of files.

This doesn't deal with the renaming problem though. But you simplify things by making a specific folder where you put all of the files from one of the programs. Then you can write a script to automatically rename files in that folder to your new file extension.

You may have trouble with an "Open File" dialogue in your program, depending on how it is set up. But if you have a single folder where all of your files are you should be able to just use that.

A more complicated, but potentially better way would be to create a proxy program. Keep all file extensions, but have them be opened by the proxy program. Have your program examine the binary and choose which type of file it is and which program to start. This will require you to spend some time writing your program, which may or may not be worth it to you.

share|improve this answer
Yes, but using a wholly different extension means you often can't open the files from within the programs. – endolith Aug 2 '11 at 2:04
yes I pointed that out. The second method I suggested won't have that problem though. – Joel Aug 2 '11 at 2:13

Microsoft Visual Studio implements your last idea. When you launch a .sln file, a small stub checks the solution version number and launches the correct version of Visual Studio (if you've got multiple versions installed).

Of course, coordination here is a bit easier since (A) the file format is designed for this and (B) they're all versions of the same software, from the same manufacturer.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .