Given a file, get the location in a separate (identically structured) directory?

Posted on


Being completely green to Windows shell and cmd scripting, I’m banging my head against this particular problem but coming up with nothing.

What I’m aiming to do is add a context menu item to right clicking on a file to launch WinMerge and compare it to that file in a separate, static directory. It shouldn’t matter if this invokes a particular cmd file that then performs the operations to resolve the directories.

For example, we have a hypothetical set of directories and files:


Right clicking on C:releasedversions1.0componentcomponentcode.cpp and selecting this will open WinMerge and compare it to C:devcomponentcomponentcode.cpp

We can assume that everything dev and 1.0 structure-wise is identical for all intents and purposes. Obviously the launch command for WinMerge itself is trivial, but I’m having trouble determining the relative paths to files inside the base code directory.


Maybe this will help you:

I have a script to automatically create self extracting zips from single files. I have added this script to the context menu for obvious reasons. What you can try is adding a command to the context menu that calls a script, the %1 in the screenshot is the full path to the right-clicked file, including the file name:

enter image description here

In essence, create a new reg key under HKCR*shell, and name it to whatever you want to appear on the context menu. Create a new key under there labeled ‘Command’, and for the default value of that key set it to the command you want to call. In your case you probably want a simple powershell script that that takes in the path as a parameter and builds a new path based on that one, and calls winMerge and passing in those two paths. Powershell is not hard to pick up, Something like


$CodeDir = "C:devcomponent"

Leave a Reply

Your email address will not be published.