Open This Folder As A Project

For years, I have been using Sublime Text 3 and have found close to negative one reasons to change text editors any time soon. It’s fast, Python scriptable, and highly supported by many plugins. One of the things I have learned from holding a single user license to Sublime Text 3 is how to make opening directories within it a convenient task. At work, I probably right click and “Open with Sublime Text 3” both folders and directories nearly 50 times a day! Even many of the photos below show a directory open with Sublime Text 3, as if it were an open project or solution in Visual Studio. Let’s break down what we do to the Windows registry to make a custom “Open with” entry:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3]
@="Open with Sublime Text 3"
"Icon"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
  00,46,00,69,00,6c,00,65,00,73,00,5c,00,53,00,75,00,62,00,6c,00,69,00,6d,00,\
  65,00,20,00,54,00,65,00,78,00,74,00,20,00,33,00,5c,00,73,00,75,00,62,00,6c,\
  00,69,00,6d,00,65,00,5f,00,74,00,65,00,78,00,74,00,2e,00,65,00,78,00,65,00,\
  2c,00,30,00,00,00

[HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 3\command]
@="C:\\Program Files\\Sublime Text 3\\sublime_text.exe %1"

[HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3]
@="Open with Sublime Text 3"
"Icon"=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
  00,46,00,69,00,6c,00,65,00,73,00,5c,00,53,00,75,00,62,00,6c,00,69,00,6d,00,\
  65,00,20,00,54,00,65,00,78,00,74,00,20,00,33,00,5c,00,73,00,75,00,62,00,6c,\
  00,69,00,6d,00,65,00,5f,00,74,00,65,00,78,00,74,00,2e,00,65,00,78,00,65,00,\
  2c,00,30,00,00,00

[HKEY_CLASSES_ROOT\Directory\Background\shell\Open with Sublime Text 3\command]
@="C:\\Program Files\\Sublime Text 3\\sublime_text.exe %V"

In summary, if you were to merge this with your Windows registry, right clicking any directory object, or its background, will give you the option to open it with Sublime Text 3. There are four entries in total, two per filesystem object. If we consider that a directory icon and directory backgrounds are two separate things, we need an icon and a command for each. Here’s what it looks like in Regedit:

The location to the icon is stored as a REG_EXPAND_SZ type, but it translates to the absolute path to the executable of Sublime Text 3, trailed by a comma and the number zero. This tells the menu item to take icon of the executable. The command key just stores what we want Windows to execute.

Passing %1 to the command translates to the absolute path to the filesystem object. For the “Directory Background” filesystem object, %V is needed. That expands to the path of the container, whether it’s a folder, the desktop, or a drive. Paste what’s above in a .reg file and merge it to have the following context menu item everywhere you are in Windows!

If you’re a true tinkerer, you will understand this has true power. You can try all kinds of different file types and executables. The above example is only true for containers, but if you study the Windows registry, nearly every component of the Windows Explorer can have customized context menu items.