-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_operations.go
42 lines (37 loc) · 916 Bytes
/
file_operations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"os"
"github.com/wailsapp/wails/v2/pkg/runtime"
)
func (a *App) SelectFile() (string, error) {
file, err := runtime.OpenFileDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select File",
Filters: []runtime.FileFilter{
{
DisplayName: "All Files",
Pattern: "*.*",
},
},
})
if err != nil {
return "", fmt.Errorf("error selecting file: %v", err)
}
return file, nil
}
func (a *App) SelectDirectory() (string, error) {
directory, err := runtime.OpenDirectoryDialog(a.ctx, runtime.OpenDialogOptions{
Title: "Select Folder",
})
if err != nil {
return "", fmt.Errorf("error selecting directory: %v", err)
}
return directory, nil
}
func (a *App) ReadFileContent(filePath string) (string, error) {
content, err := os.ReadFile(filePath)
if err != nil {
return "", fmt.Errorf("error reading file content: %v", err)
}
return string(content), nil
}