1

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:

C:\released\versions\1.0\lib\libcode.cpp
C:\released\versions\1.0\component\componentcode.cpp
C:\dev\lib\libcode.cpp
C:\dev\component\componentcode.cpp

Right clicking on C:\released\versions\1.0\component\componentcode.cpp and selecting this will open WinMerge and compare it to C:\dev\component\componentcode.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.

1 Answer 1

1

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

param([String]$Path=$null)

$CodeDir = "C:\dev\component\"

$File1 = $Path
$File2 = "$CodeDir$(Get-ItemProperty $Path).Name"

Start-Process WinMerge.exe -Argumentlist "$File1 $File2"

There's obviously some optimizations that could take place there but hopefully you see the point. I don't have WinMerge so I don't know the correct syntax, but this is the outline of what needs to take place. To call your script you can look at my screenshot and replace my script path with yours, you will need powershell installed which comes standard on Vista+.

2
  • 1
    Thanks! It looks like a Powershell script will be just what I need. I should be able to get the relative directory easy enough through Directory.Parent objects and so on.
    – C-Mart
    Jun 5, 2013 at 20:37
  • @C-Mart you could do that, or add the \..\.. to the path as in linux also.
    – MDMoore313
    Jun 5, 2013 at 23:45

You must log in to answer this question.

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