Advertisement
Thoughtcoder411

Sys.walk.python

May 2nd, 2024
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.09 KB | None | 0 0
  1. import os
  2. import sys
  3. import platform
  4. import winreg
  5.  
  6. def get_system_information():
  7.     system_info = {
  8.         'Operating System': platform.platform(),
  9.         'Python Version': sys.version,
  10.         'Desktop Directory': os.path.join(os.path.expanduser('~'), 'Desktop'),
  11.         'Desktop Icons': os.listdir(os.path.join(os.path.expanduser('~'), 'Desktop'))
  12.     }
  13.  
  14.     known_folders = {
  15.         'Documents': '{FDD39AD0-238F-46AF-ADB4-6C85480369C7}',
  16.         'Downloads': '{374DE290-123F-4565-9164-39C4925E467B}',
  17.         'Music': '{4BD8D571-6D19-48D3-BE97-422220080E43}',
  18.         'Pictures': '{33E28130-4E1E-4676-835A-98395C3BC3BB}',
  19.         'Videos': '{18989B1D-99B5-455B-841C-AB7C74E4DDFC}'
  20.     }
  21.  
  22.     for folder_name, folder_guid in known_folders.items():
  23.         try:
  24.             with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders") as key:
  25.                 folder_path = winreg.QueryValueEx(key, folder_guid)[0]
  26.                 system_info[folder_name + ' Path'] = folder_path
  27.         except FileNotFoundError:
  28.             pass
  29.  
  30.     system_info['System Paths'] = {name: value for name, value in os.environ.items()}
  31.  
  32.     return system_info
  33.  
  34. def write_system_information_to_files(system_info):
  35.     folder = os.path.join(os.path.expanduser('~'), 'Desktop', 'autonomie', 'sys.inf')
  36.     os.makedirs(folder, exist_ok=True)
  37.  
  38.     info_filepath = os.path.join(folder, 'system_info.txt')
  39.     with open(info_filepath, 'w') as f:
  40.         for key, value in system_info.items():
  41.             f.write(f"{key}: {value}\n")
  42.  
  43.     paths_filepath = os.path.join(folder, 'system_paths.txt')
  44.     with open(paths_filepath, 'w') as f:
  45.         f.write("System Paths:\n")
  46.         for path_name, path_value in system_info['System Paths'].items():
  47.             f.write(f"{path_name}: {path_value}\n")
  48.  
  49.     print("System information has been written to:", info_filepath)
  50.     print("System paths have been written to:", paths_filepath)
  51.  
  52. if __name__ == "__main__":
  53.     system_info = get_system_information()
  54.     write_system_information_to_files(system_info)
  55.  
Tags: python WIP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement