Adding a custom "new folder" to the context menu of Windows Explorer

I often use the current date and time to create new folders, and I created a program that does this (i.e., it takes one argument and then creates a new folder based on the current date and time and argument).

I was wondering how I can do this to get the “new date folder” displayed in my context menu in Windows Explorer (just below the “New folder”), and that it automatically adds the date and time in advance and allows the user to enter a name. This is actually very similar to the standard "new folder", except that by default the name "New folder" should be "DateTime" and the default text should not be marked.

Any ideas? Thanks.

+4
source share
2 answers

After playing a little, I figured out a way to add a basic version of this by simply editing the registry. It does not request a name (it simply uses the basic format DD.MM.YYYY HH; MM; SS) and does not enter the rename mode of the explorer:

Explorer New menu

Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Software\Classes\.NewDirectoryBasedOnDate] @="NewDirectoryBasedOnDate" [HKEY_CURRENT_USER\Software\Classes\.NewDirectoryBasedOnDate\ShellNew] "Command"="\"CMD\" /D /E:ON /c for /F \"tokens=1-9 delims=.,\\:/\" %%A IN (\"%%date%%.%%time%%\") DO for /F \"tokens=*\" %%a IN (\"%1\") do md \"%%~dpa\\%%A.%%B.%%C %%D;%%E;%%F\"" "nullfile"=hex: [HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate] "FriendlyTypeName"="Directory Based On Date" [HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate\DefaultIcon] @="shell32.dll,3" [HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate\Shell\open] "LegacyDisable"=hex: [HKEY_CURRENT_USER\Software\Classes\NewDirectoryBasedOnDate\Shell\open\command] @="." 

I tested it only on WinXP and hacked a bit (I had to add a fake Shell\open\command key to get a new menu entry)

Changing the command to wscript.exe //nologo "C:\path\to\NewDateDir.wsf" "%1" and saving the following code in NewDateDir.wsf will give you the following:

Explorer New menu and WSH script

 <?xml version="1.0" ?><job><script language="VBScript"><![CDATA[ if WScript.Arguments.Count < 1 then MsgBox("Bad parameter!") WScript.Quit(1) end if Set FSO=CreateObject("Scripting.FileSystemObject") Function StrFilter(s,ch,rep) StrFilter=Join(Split(s,ch,-1),rep) End Function basedir=FSO.GetParentFolderName(WScript.Arguments(0)) defname=Date&" "&Time defname=StrFilter(defname,"/",".") defname=StrFilter(defname,":",";") name=InputBox("New folder in "&basedir,"New folder",defname) if not IsEmpty(name) and Len(name) > 0 then FSO.CreateFolder(FSO.BuildPath(basedir,name)) end if ]]></script></job> 

Even if you decide to write a shell extension, I think that activating the rename mode for researchers will be difficult, especially if you want a partial selection. You should also remember that other programs can implement shell context menus, so you cannot use all kinds of undocumented explorer materials.

+7
source

You need to implement a shell extension, in particular a context menu. Here is a pretty good walk on how to do this. There is also lower-level documentation on MSDN here (for context menus in particular) and here (for shell extensions in general). For your specific case, I think you registered the shell extension in the "Directory \ Background" section.

0
source

Source: https://habr.com/ru/post/1338068/


All Articles