优化:动态获取系统所有盘符(C/D/E/F等)
This commit is contained in:
37
app.go
37
app.go
@@ -140,14 +140,39 @@ func (a *App) GetCommonPaths() (map[string]string, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return map[string]string{
|
||||
"home": homeDir,
|
||||
"desktop": filepath.Join(homeDir, "Desktop"),
|
||||
// 获取所有可用驱动器(Windows)
|
||||
drives := getSystemDrives()
|
||||
|
||||
paths := map[string]string{
|
||||
"home": homeDir,
|
||||
"desktop": filepath.Join(homeDir, "Desktop"),
|
||||
"documents": filepath.Join(homeDir, "Documents"),
|
||||
"downloads": filepath.Join(homeDir, "Downloads"),
|
||||
"root_c": "C:\\",
|
||||
"root_d": "D:\\",
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 动态添加所有盘符
|
||||
for i, drive := range drives {
|
||||
key := fmt.Sprintf("root_%s", drive[:1])
|
||||
paths[key] = drive
|
||||
_ = i // 避免未使用变量警告
|
||||
}
|
||||
|
||||
return paths, nil
|
||||
}
|
||||
|
||||
// getSystemDrives 获取系统所有可用驱动器
|
||||
func getSystemDrives() []string {
|
||||
var drives []string
|
||||
|
||||
// Windows: 检查 A-Z 所有盘符
|
||||
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
|
||||
path := string(drive) + ":\\"
|
||||
if _, err := os.Stat(path); err == nil {
|
||||
drives = append(drives, path)
|
||||
}
|
||||
}
|
||||
|
||||
return drives
|
||||
}
|
||||
|
||||
// ========== 数据库连接管理接口 ==========
|
||||
|
||||
Reference in New Issue
Block a user