testShellFolder.py 585 B

123456789101112131415161718192021
  1. from win32com.shell import shell
  2. from win32com.shell.shellcon import *
  3. sf = shell.SHGetDesktopFolder()
  4. print("Shell Folder is", sf)
  5. names = []
  6. for i in sf: # Magically calls EnumObjects
  7. name = sf.GetDisplayNameOf(i, SHGDN_NORMAL)
  8. names.append(name)
  9. # And get the enumerator manually
  10. enum = sf.EnumObjects(0, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS | SHCONTF_INCLUDEHIDDEN)
  11. num = 0
  12. for i in enum:
  13. num += 1
  14. if num != len(names):
  15. print("Should have got the same number of names!?")
  16. print("Found", len(names), "items on the desktop")
  17. for name in names:
  18. print(name)