I'm using SharpShell to write a tiny new shell context menu item that copies the currently selected files to a new subfolder, then prompts the user for the directory's new name.
Searching StackOverflow, I found this answer. However, I'd like to do the same in SharpShell.
I will somehow have to fire SVSI_EDIT at it, which I can find buried deep in SharpShell.Interop, but I'm not sure how any of this works. I can't find any documentation or code samples whatsoever.
(Edit: I think finding out how to get a Pidl from a file name would be a good start, but maybe I don't really need that at all?)
You can start creating a project with SharpShell to register a new shell context menu like in this tutorial.
Here, we have to define a class implementing
SharpContextMenu. For simplicity we will create the menu for any filetype and always show it:But I'm sure you've done all this, the problem here is to implement the
CopyFiles()method.One way to do this is showing a dialog asking for the name of the folder, something like this:
Then, implement
CopyFiles()like so:In above code, we asked for the name of the folder, then create the folder and finally move selected files to that folder.
However, if you want to do it using Rename command in Windows Explorer we can start by importing some needed Win32 functions:
ILCreateFromPathallows us get the PIDL from a filename.SHOpenFolderAndSelectItemsallow us select the file and send rename command.ILFreefrees unmanagedPIDLcreated.With these Win32 functions we can defines
CopyFiles()as follows:We can't use
SharpShell.Interop.Shell32since the only method available in this class isShellExecuteEx()which is used to launch new processes.