Question

Let me elaborate. By "items" I mean all the items you see one the desktop (Windows) which includes "My Computer", "Recycle Bin", all the shortcuts etc. If I select all the items on the desktop I get the count in the properties displayed. It is this count I want, programmatically.

The problem I face:

The desktop as we see has items from my account, also the All Users's desktop items and also other shortcuts like "My Computer", "Recycle Bin". In total, 3 things. So I can't just get the item count from the physical path to Desktop directory. So this fails:

int count =
    Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder
                                                            .DesktopDirectory)
                      ).Length;

I know SpecialFolder.Desktop stands for the logical desktop as we see. But this fails again since GetFolderPath() again gets the physical path of user's desktop:

int count = 
    Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder
                                                            .Desktop)
                      ).Length;

What is the right way to get total count on the user's desktop?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top