If a program and a folder have the same name, the shell prefers the program

Date:November 18, 2004 / year-entry #397
Tags:history
Orig Link:https://blogs.msdn.microsoft.com/oldnewthing/20041118-00/?p=37263
Comments:    26
Summary:If you have both a folder named, say, C:\Folder and a program named C:\Folder.exe and you type C:\Folder into the Start.Run dialog, you get the program and not the folder. Why is that? Because it is common to have D:\Setup.exe D:\Setup\... where there is a setup program in the root, as well as a setup...

If you have both a folder named, say, C:\Folder and a program named C:\Folder.exe and you type C:\Folder into the Start.Run dialog, you get the program and not the folder.

Why is that?

Because it is common to have

 D:\Setup.exe D:\Setup\... 

where there is a setup program in the root, as well as a setup folder containing files needed by the setup program.

Before Windows 95, you couldn't open a folder by typing its name. (If you wanted to view it in File Manager, you had to run File Manager explicitly.) As a result, programs written for earlier versions of Windows would have instructions like

  • Insert the floppy disk labelled "Setup". (CDs were for the rich kids.)
  • From Program Manager, click File, then Run.
  • In the dialog box, type "A:\SETUP" and press Enter.

Since there was no such thing as "opening a folder", the only option was to run the program A:\SETUP.EXE.

Windows 95 was required to prefer the program over the folder in order that those instructions would remain valid (substituting the Start button for the File menu).

And each version of Windows that prefers the program over the folder creates an environment wherein people who write setup programs rely on that preference, thereby securing this behavior for the next version of Windows.

But what if you really want to open the folder?

Append a backslash to force the path to be interpreted as a folder (A:\SETUP\).


Comments (26)
  1. A says:

    Append a backslash to force the path to be interpreted as a folder (A:SETUP).

    Probably should be noted that this only works on XP and later. Prior versions appear to just discard trailing backslashes.

  2. Ben Cooke says:

    Indeed. I remember on Windows 95 I would often try to run c:windowscommand to get the directory full of DOS command programs but it would actually run c:windowscommand.com.

    Thankfully, in NT-based Windows command.com lives in the system32 directory so this conflict doesn’t exist.

  3. Aswin Gunawan says:

    Pardon my stupid question, are the stuffs under "HKLMSOFTWAREMicrosoftWindowsCurrentVersionRun" executed under the shell context? Reason I ask is it seems to have a different priority to what you outlined above. For example, you have a folder called "C:Program FilesFooAppFoo" and another folder called "C:Program FilesFooAppFoo Bar" and then on RUN key you put something like "C:Program FilesFooAppFoo BarBlah.exe" but without quoting it. I know that this becomes ambiguous because of the space, and quoting it will solve the ambiguity. But if I run that cmd-line from Start.Run without quoting it, it will execute Blah.exe. However, when Windows starts and executes the RUN key, "C:Program FilesFooAppFoo" folder will be opened instead. Please shed me some light in this matter, thanks.

  4. Raymond Chen says:

    Why should the two behave the same? One is an end-user control and the other is a programmatic interface.

  5. Aswin Gunawan says:

    Then what is the preference of "programmatic interface"?

  6. Raymond Chen says:

    I’ll take this up as a future topic. In the future, please put topic suggestions in the suggestion box instead of hijacking another comment thread.

  7. You’ve got to wonder, if Microsoft were faced with this decision today would they still give preference to the file over the folder? I think, given all the security concerns nowadays, they would take go the safer route and give preference to the folder.

  8. Aaargh! says:

    Why was the decision made to automagically append the .exe ?

    The decision to run c:folder.exe instead of c:folder when the user types C:folder into start->run seems a bit weird to me, since there is no executable with the name c:folder (it’s called c:folder.exe), but there IS a directory with that name. If I was a user with no prior experience with Win32 I would not expect that behaviour.

  9. Mike Edwards says:

    It’s very common to not require users to type in full command names, to give them less typing to do. If you want to run it, it must be a program, therefore it’s probably called ‘.exe’ so it gets added. Hence the original instructions in the example being ‘a:setup’ to run the setup.exe program.

  10. Robert Moir says:

    "If I was a user with no prior experience with Win32 I would not expect that behaviour."

    Actually yes you would. If you were a user with no prior experience of windows you wouldn’t have found and turned off the feature of explorer that hides the extension of known file types, and hence you would never know the setup program was really named "setup.exe" rather than simply "setup"

  11. Moi says:

    The two (end user control and programmatic interface) should behave the same because the people who program to the programmatic interface are users too, probably before they were programmers.

  12. Dhericean says:

    Moi:

    This way lies all the problems that lead to a number of confusions and compatibility shims.

    The End User interface is for ease of use. Any ambiguity can be addressed by the user when they use it. This is not often just a thin interface over the API.

    The programmatic interface is for clear and non-ambiguous invocation of operations (as the programmer is not there at run-time to correct any confusion). That is the reason there is (or at least should be) a clear published interface of what should be used and how it behaves.

    The difference is that the target audience for the first is users and power users, and the second is programmers. As a Mort I fall somewhat between these but if I want some of the friendlier behaviour I have to program it myself (or find someone else who has already done it); just as the end user interface programmers did.

  13. Kevin R says:

    Another seeming discrepancy. If I leave off the path, and just type the exe (or folder) name into Start->Run, the FOLDER takes precedence over the exe.

    For example, normally if you type "mmc" into Start->Run, up will come mmc.exe. But if you create a folder named MMC within HOMESHARE (or HOMEDRIVE?) and try again, up will come that folder…

  14. Moi says:

    Dhericean> The programmatic interface is for clear and non-ambiguous invocation of operations

    So is the UI. You would prefer that it is ambiguous?

    That aside, clearly there is already an ambiguity since the two are different.

    >the target audience for the first is users and power users, and the second is programmers

    Programmers are users. Should they read the documentation? Certainly, however the fact is that much documentation is not clear, and you can’t blame them for falling back on their knowledge of the UI when they see a function which appears to offer the same functionality.

  15. Raymond Chen says:

    Kevin: That has nothing to do with folder/exe priority. That’s search path priority. The folder/exe rule is a tiebreaker, not the primary rule.

  16. Cooney says:

    Why should the two behave the same? One is an end-user control and the other is a programmatic interface.

    Why should they be different? Every additional permutation is one more level of complexity, one more place for bugs to hide, and one more place for developers to make assumptions.

  17. Matt says:

    "Indeed. I remember on Windows 95 I would often try to run c:windowscommand to get the directory full of DOS command programs but it would actually run c:windowscommand.com.

    Thankfully, in NT-based Windows command.com lives in the system32 directory so this conflict doesn’t exist."

    In a question to Raymond, that’s only relevent because of this comment – who on earth decided that the "Prevent access to the command prompt" policy in group policy would only prevent access to cmd.exe and not …system32command.com??

    It makes that policy setting only a smidgeon of useless! Surely, despite command.com’s DOS heritage and legacy scripts, command.com could have respected that policy.

  18. Matt says:

    (I considered correcting grammar and spelling in the above post after I hit submit, but hope Raymond will answer despite it given it’s my birthday)

  19. Matt says:

    (… despite those …)

  20. Raymond Chen says:

    Please post off-topic questions to the suggestion box instead of hijacking a thread.

  21. Matt says:

    You didn’t have a topic for my birthday and the suggestion box seems buried approx 50 links in

  22. Raymond Chen says:

    buried? It’s there on the left hand side under "Links". Click on "Suggestion box".

  23. Matt says:

    It’s (the box is) exactly link number 48 (I hope).

    It just seems it should be higher if you want people going there instead of your very attractive content and comments (surely people are likely to get attracted to that well before link 48!)

    My question before was even more related to the most recent comments, given the facilitating comment I quoted.

    I’ll shut up now for the sake of freeing innocent hostages from this thread hijack.

  24. Raymond Chen says:

    I can’t do anything about that – .Text puts the archive links in front of the custom links.

  25. Anonymous says:

    Sorry Raymond, if you consider this comment as hijacking thread.

    Dhericean > The End User interface is for ease of use. Any ambiguity can be addressed by the user when they use it.

    Since when the user knows how to resolve ambiguity? Aren’t you expecting too much from your user?

  26. What’s interesting:

    What Raymond tell us here applies only to the Run-Dialog.

    I have my taskbar configured to constantly display the address line (I use that for quick access to deeply nested folders and stuff. It’s even faster than Windows-R)

    In this address-bar, folders take precedence over same-named .EXE’s.

    Philip

Comments are closed.


*DISCLAIMER: I DO NOT OWN THIS CONTENT. If you are the owner and would like it removed, please contact me. The content herein is an archived reproduction of entries from Raymond Chen's "Old New Thing" Blog (most recent link is here). It may have slight formatting modifications for consistency and to improve readability.

WHY DID I DUPLICATE THIS CONTENT HERE? Let me first say this site has never had anything to sell and has never shown ads of any kind. I have nothing monetarily to gain by duplicating content here. Because I had made my own local copy of this content throughout the years, for ease of using tools like grep, I decided to put it online after I discovered some of the original content previously and publicly available, had disappeared approximately early to mid 2019. At the same time, I present the content in an easily accessible theme-agnostic way.

The information provided by Raymond's blog is, for all practical purposes, more authoritative on Windows Development than Microsoft's own MSDN documentation and should be considered supplemental reading to that documentation. The wealth of missing details provided by this blog that Microsoft could not or did not document about Windows over the years is vital enough, many would agree an online "backup" of these details is a necessary endeavor. Specifics include:

<-- Back to Old New Thing Archive Index