I would like to add an entry to the context menu for folders, but only have it show in the context menu IF the folder in question contains files of a certain type (in this case, only if the folder contains .avi files). Is this possible?

I'm sure I've seen at least one program which only had its context menu entry shown in certain folders - though I can't for the life of me remember what it was.


I know this is an old thread, but since there wasn't much on google for this topic.... I wanted to add a little more... Mostly this is just tacking onto what harrymc mentioned, but maybe this will help those less comfortable with registry editing...

First, there are actually tons of API methods available from the System object mentioned above. For example, instead of ItemName you could also check System.FileName (which worked better for me) or System.ItemFolderPathDisplay ...

Second, the search syntax is somewhat involved but actually gives you a lot of options. You can use the standard DOS wildcards in the AppliesTo test (e.g. "?" for exactly 1 character, "*" for 0 or more characters). You can use a variety of operators against the name... such as equal, not equal, contains, starts with, ends with, etc. You can string together multiple conditions with "AND" or "OR" keywords (or use "NOT").. It seems like you can even do some SQL-ish sort of search syntax, but I haven't been able to get these to work natively via the registry (I could just have the syntax wrong... not sure).

3) While I haven't found the solution to the question asked, the following registry scripts shows how you can show or hide context menu items based on folder name and location. I just have it poppin g up a command prompt but you could easily change to whatever else.

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\# Ends With '_mydata']

[HKEY_CLASSES_ROOT\Folder\shell\# Ends With '_mydata'\command]
@="C:\\Windows\\System32\\cmd.exe /k cd /d \"%1\""

[HKEY_CLASSES_ROOT\Folder\shell\# Starts with 'C:-slash-[Videos]']
"AppliesTo"="System.ItemFolderPathDisplay:~< \"C:\\[VIDEOS]\""

[HKEY_CLASSES_ROOT\Folder\shell\# Starts with 'C:-slash-[Videos]'\command]
@="C:\\Windows\\System32\\cmd.exe /k cd /d \"%1\""

[HKEY_CLASSES_ROOT\Folder\shell\# Starts with 'C:-slash-[Videos]' AND ends with '_mydata']
"AppliesTo"="System.FileName:\"*_mydata\" AND System.ItemFolderPathDisplay:~<\"C:\\\""

[HKEY_CLASSES_ROOT\Folder\shell\# Starts with 'C:-slash-[Videos]' AND ends with '_mydata'\command]
@="C:\\Windows\\System32\\cmd.exe /k cd /d \"%1\""
| improve this answer | |
  • This is awesome, I like to add a context menu to open my local server files in a browser for my dev server, this allow me to only show the menu if the files reside under my server folder instead of adding to all my files,thanks for sharing – JasonDavis Jan 12 '13 at 23:04
  • This: "AppliesTo"="System.FileName:\"_mydata\" AND System.ItemFolderPathDisplay:~<\"C:\\\"" should read: "AppliesTo"="System.FileName:\"_mydata\" AND System.ItemFolderPathDisplay:~<\"C:\\[VIDEOS]\"" – Luca Gibelli Jul 9 '15 at 13:23

It's certainly possible to write a context-menu handler whose entry that will only show up in the menu if certain files exist in the directory. A context-menu handler is a program that is free to decide whether to show up or not, although this might slow down the appearance of the context-menu for folders.

The only general mechanism in Windows for this to happen is Windows Search Advanced Query Syntax. One of the new features in Windows 7 is the addition of the "AppliesTo" value for static context menu items. This lets a static item be shown or hidden based on the result of an AQS query.

In this example, the DefaultAppliesTo value makes this verb the default for any file with the word "exampleText1" in its file name. The AppliesTo value enables the verb for any file with "exampleText1" in the name. The HasLUAShield value displays the shield for files with "exampleText2" in the name.

            DefaultAppliesTo = System.ItemName:"exampleText1"
            HasLUAShield = System.ItemName:"exampleText2"
            AppliesTo = System.ItemName:"exampleText1"

As AQs is not well-documented, I haven't been able to find the syntax for querying a folder's content.

| improve this answer | |

Filemenu Tools will let you do this, at least within it's own context menu.

| improve this answer | |
  • Unfortunately, this doesn't do what I'm looking for. It lets me add things to the context menu for files of a certain type, ie I can show an entry when I right click on .avi files - that is not quite what I'm after though. What I want to be able to do is right click on the folder containing the .avi file, and have the entry on that - and only have that entry there for folders that contain .avi files. – Dal Hundal Sep 3 '10 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.