12

Many Linux file managers identify file type regardless of extension. For example, when I double click on a text file with whatever extension or no extension at all, it looks the contents of file and determines if it is a text file and opens a text editor. This is extremely helpful when editing conf files.

Is there a file manager on Windows that has this feature?

1
  • Where would the MIME type be stored? Or do you want the file manager to analyze the file's content and try to estimate the MIME type? Oct 19, 2020 at 17:34

1 Answer 1

1

Ooh this would be awesome! Except Windows doesn't work like this.

Unfortunately, both by design and by convention, Windows enforces file type associations by way of file extensions. That is to say, the "name" of the file goes to the left of the period, and the file type goes to the right of the period (file-name.file-type).

Windows does not necessarily care about the content or format of files. This is one reason why file extensions are hidden by default in Windows - to ensure novice users do not accidentally change the file extension (which may result in an extremely negative experience if someone wasn't aware of the behavior).

The documentation on how Windows handles this makes it clear: https://docs.microsoft.com/en-us/windows/win32/shell/fa-file-types

Files with a shared common file name extension (.doc, .html, and so on) are of the same type.

Problem Set

There are actually two problems here:

  1. Determining a file's "type" (format)
  2. Executing the correct (desired, intended) Program to open, read, or process the file.

Even if we can determine the correct file type, there still needs to be a standard and consistent mechanism to associate any arbitrary file format - identified by extension or content - with an available program. I don't know about you, but I have many programs on my computer which can all easily read text files, images, and other formats. How does the computer know which one to use?

Custom File Type Associations

One solution for your specific use case - double-clicking .conf files on Windows - is making a custom File Type Association. This entails:

  • Identifying the ProgID of the installed program/application you want to use to open the file, for example Visual Studio Code.
  • Update the Windows Registry to open the file with the application.

Here's an example Windows Registry Editor file that configures the .conf file type to open with Code.exe:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\.conf]
@="Configuration.File"
"Content Type"="text/x-conf"

[HKEY_CLASSES_ROOT\.conf\OpenWithProgids]
"VSCode.conf"=""

[HKEY_CLASSES_ROOT\VSCode.conf]
@="Configuration File"
"AppUserModelID"="Microsoft.VisualStudioCode"

[HKEY_CLASSES_ROOT\VSCode.conf\DefaultIcon]
@="C:\\Program Files\\Microsoft VS Code\\resources\\app\\resources\\win32\\config.ico"

[HKEY_CLASSES_ROOT\VSCode.conf\shell]

[HKEY_CLASSES_ROOT\VSCode.conf\shell\open]
"Icon"="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\""

[HKEY_CLASSES_ROOT\VSCode.conf\shell\open\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%1\""

I created this by extracting the HKCR:.py and HKCR:VSCode.py registry entries which is for the the "Python" (.py) file type association for VS Code, and replaced all instances of .py with .conf.

*nix is different... kinda

On Linux and Unix-based systems, there is no such absolute requirement that all files have file extensions to determine their file type. That said, the "file extension means file type" paradigm is both extremely common and often mandatory, even in Linux.

As an example, System-wide Shell profile files in /etc/profile.d/ must end in .sh in order for the shell to load them on startup.

Another example from something less archaic might be systemd. To quote from the Ubuntu 20.04 systemd.service (5) man page:

A unit configuration file whose name ends in .service encodes information about a process controlled and supervised by systemd.

There is no technical requirement that a systemd service file have that naming convention, other than by design (just like Windows!).

Default Behavior

It could be that your experience of opening a text file on Linux opening a text editor, might be because your text editor was the default file handler for any "unknown" file type?

Headers, Magic Numbers and File Signatures

Another possibility of the behavior you mentioned of opening a text editor when you "double click on a text file with whatever extension or no extension at all" is rooted in the complexities of determining a file format by evaluating some or all of the contents of the file (instead of the file extension).

Here are three common approaches to this:

Name Description
Headers Binary or Character data either at the start or the end of the file. Typically contain additional information or instructions on how to use or parse the file. Examples: zip files contain the file list, and png files contain the image width, height, and color bit depth among other properties.
Magic Number A unique multi-byte identifier at the immediate beginning of the file. For example, GIF images start with ASCII GIF87a or GIF89a.
Structural Metadata Often used for text/character files, looks for specific start and end markers, such as { and } for JSON, , for CSV, < and > for XML.

Tools

file (1)

Nearly all *nix distributions come with the file (1) command, which use a database of magic (5) files to specify (programmatically) exactly how to determine a file format by examining some or all of its contents. The magic (5) system is probably what your Linux Window/File manager is using to determine the file type.

file (1) on Windows

file (1) is also available on Windows: http://gnuwin32.sourceforge.net/packages/file.htm

However this is a command line interface, and not directly integrated into Windows Explorer, and does not otherwise provide a GUI.

TrID

While researching this, I found TrID which is an interesting alternative, as it gives a percentage probability of a given file type.

TrIdNet - GUI

TrIdNet provides a GUI interface to trid.

DROID

DROID - from the UK National Archives, built to perform automated batch identification of file formats.

Unfortunately while these programs can tell you what the files are, they do not have the ability to identify, open and instruct the desired program to read/process that file for you.

Build it?

Given the above tools and knowledge, it's absolutely possible to build a File Manager on Windows that uses libmagic, DROID, TrID or a combination thereof, to open files based on content rather than by extension. But unfortunately, I am not aware of anything that exists today.

In addition, using the solution in superuser.com/How to set the default program for opening files without an extension in Windows?, a custom program could be set to handle any unknown file extension (or files without an extension), determine the file type, and perhaps offer to open a program or two.

1
  • This looks like a comment, rather than an answer. While the explanation is great, it doesn't answer with a concrete recommendation.
    – Alejandro
    Dec 23, 2021 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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