How to get the total number of items on the (logical) desktop (C#)
-
30-10-2019 - |
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