mirror of
https://github.com/yeongpin/cursor-free-vip.git
synced 2025-09-27 05:26:03 +08:00
修正 windows 环境下用户目录的获取方式
This commit is contained in:
11
utils.py
11
utils.py
@@ -6,7 +6,16 @@ import random
|
||||
def get_user_documents_path():
|
||||
"""Get user documents path"""
|
||||
if platform.system() == "Windows":
|
||||
return os.path.expanduser("~\\Documents")
|
||||
try:
|
||||
import winreg
|
||||
# 打开注册表
|
||||
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders") as key:
|
||||
# 获取 "Personal" 键的值,这指向用户的文档目录
|
||||
documents_path, _ = winreg.QueryValueEx(key, "Personal")
|
||||
return documents_path
|
||||
except Exception as e:
|
||||
# fallback
|
||||
return os.path.expanduser("~\\Documents")
|
||||
else:
|
||||
return os.path.expanduser("~/Documents")
|
||||
|
||||
|
Reference in New Issue
Block a user