When I tell the file or folder picker that I want only file system files and folders, why does it still show virtual folders?

Raymond Chen

You can ask a file picker dialog to limit itself to files in the file system by passing the FOS_FORCE­FILE­SYSTEM flag. There is an analogous BIF_RETURN­ONLY­FS­DIRS flag for the folder picker.

But if you pass this flag, you’ll still see virtual folders in the user interface. Things like Network and My Computer This PC. And if the user picks it, the OK button grays out, which is confusing. Why are these virtual folders showing up when I explicitly asked that they not show up?

Well, that’s not what you asked.

You asked that the user be able to select only file system files or folder. You didn’t ask that non-file-system object be removed from view.

But why are these non-file-system objects shown in the view if the user can’t select them?

Because there might be a file system object inside them.

The shell namespace has two attributes related to the file system. One is SFGAO_FILE­SYSTEM, which means that the item is itself in the file system. The other is SFGAO_FILE­SYS­ANCESTOR which means that the item or its children are in the file system.

If an item has the SFGAO_FILE­SYS­ANCESTOR attribute, then it will show up in the “make sure the user picks an item in the file system” dialogs: Even if the item itself is not a file system item, it may contain a file system item, so the dialog shows the item so the user can navigate into it to find the actual file system item.

The SFGAO_FILE­SYS­ANCESTOR attribute is like a sign that says “This way to the file system.”

If the file and folder picker dialogs showed only file system objects and not also file system ancestors, then your dialog would be pretty blank, seeing as the root items like This PC and Network are themselves not file system items. But if you want to pick something from your D: drive, you’ll probably need to go through This PC to get there.

 

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Ian Boyd 0

    I also miss My Computer.

Feedback usabilla icon