import os
# 查看桌面路径
desktop_path = os.path.join(os.environ['USERPROFILE'], 'Desktop')
print("==",desktop_path)
# 拼接路径
desktop_path = os.path.join(desktop_path, "path2")
print("==",desktop_path)
# 创建目录
if not os.path.exists(desktop_path):
os.makedirs(desktop_path)
# 创建文件
file_name = "example.txt"
full_file_path = os.path.join(desktop_path, file_name)
with open(full_file_path, 'w') as f:
f.write("这是测试内容。\n")
print(f"{file_name} 已成功创建于您的桌面上!")