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?
The Windows shell has full and comprehensive support for this.
SHGetDesktopFolder()
to get an IShellFolder
for the desktop.IShellFolder::EnumObjects()
to get the contents.This Code Project article gives some usage examples from a C# perspective.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With