22 lines
716 B
Go
22 lines
716 B
Go
package dialog
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
func PickFolder() (string, error) {
|
|
script := `Add-Type -AssemblyName System.Windows.Forms; $dialog = New-Object System.Windows.Forms.FolderBrowserDialog; $dialog.ShowNewFolderButton = $false; if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) { [Console]::Write($dialog.SelectedPath) }`
|
|
cmd := exec.Command("powershell", "-NoProfile", "-STA", "-Command", script)
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return "", fmt.Errorf("folder selection failed: %s", strings.TrimSpace(string(out)))
|
|
}
|
|
path := strings.TrimSpace(string(out))
|
|
if path == "" {
|
|
return "", fmt.Errorf("folder selection canceled")
|
|
}
|
|
return path, nil
|
|
}
|