Windows ConfidentialWindows Explorer Doesn't Do Text

Raymond Chen

Once upon a time there was the Send To X PowerToy. It let you do neat things such as selecting a bunch of files, right-clicking, and then selecting Send To Clipboard as Names. As expected, this copied the names of the selected files to the clipboard.

This was certainly a useful PowerToy, but why did it have to exist in the first place? Why can't I just copy the files in Windows® Explorer and then paste them as text to get their file names? Or better yet, why can't I simply drag files out of Windows Explorer and drop them into Notepad to get the names?

We tried it, but it didn't work.

Data transfer, whether via the clipboard or via drag and drop, is mediated by OLE data objects, represented by the IDataObject interface. A data object offers a variety of formats. Some clipboard formats, including text and bitmaps, have been around since the beginning of Windows. Others have been added over time. When file drag and drop capabilities first came to Windows, it took the form of an HDROP. You could pass this to functions such as DragQueryFile, for example, to extract the file names. When you copy something to the clipboard from Windows Explorer, the resulting data object offers, among other things, the aforementioned HDROP, the file contents, and a file group descriptor. But one of the formats you won't see offered by the data object is text.

When a drop target (a thing you can drop objects onto) is told that a data object is being dragged over it or dropped onto it, the drop target asks the data object "Whaddya got?" The data object responds by listing all the formats it supports, in descending order of preference. In other words, the first format returned by the data object is the format that best describes the object. Then comes the next-best format, and so on, until you get to the last format, which is just a pale shadow of the original object. For example, the data object that represents some objects being dragged out of a Windows Explorer window would probably offer a shell ID list first, since that is a nearly perfect representation of the contents of a Windows Explorer window. Next on the list might be a file group descriptor, followed by the file contents, and then an HDROP.

Back in 1998, the shell team tried adding plain text to the list of formats offered, putting it at the very end of the list. This essentially said, "if you are really desperate, at least you can get some text out of me (namely, the list of files)." Unfortunately, what happened was that a large number of programs were distracted by the shiny text format and said, "Ooooh, I like text." These programs went straight for the text format that contained nothing more than a list of files. As a result, when you dragged a file from Windows Explorer and proceeded to drop it into a document, the program just inserted the file name instead of inserting the file itself into the document.


Due to the strongly negative application compatibility feedback, this change was reversed. As a result, when you drag and drop or paste files that are copied from Windows Explorer, the shell data object does not offer the file names as text.

Windows Vista®, however, rights this age-old wrong by giving you a way to copy the path as text: hold the shift key when you right-click in order to get the extended context menu. This will present the new Copy as Path option. No PowerToy necessary.

Raymond Chen's Web site, The Old New Thing, and identically titled book (Addison-Wesley, 2007) deal with Windows history and Win32 programming. He leaves the job of operationalizing mechanisms to others.

© 2008 Microsoft Corporation and CMP Media, LLC. All rights reserved; reproduction in part or in whole without permission is prohibited.