-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgo_cli_scripts_create_output.go
More file actions
62 lines (51 loc) · 1.56 KB
/
go_cli_scripts_create_output.go
File metadata and controls
62 lines (51 loc) · 1.56 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"fmt"
"github.com/windmillcode/go_cli_scripts/v6/utils"
"os"
"strings"
)
func main() {
folderPaths := []string{
utils.ConvertPathToOSFormat("..\\utils"),
}
files := []string{}
for _, folderPath := range folderPaths {
dirParams := utils.TraverseDirectoryParams{
RootDir: folderPath, // Specify your directory here
Predicate: func(path string, info os.FileInfo) {
// Action to perform on each .dart file that is not a _test.dart or g.dart file
fmt.Println("Found dart file:", path)
files = append(files, path)
},
Filter: func(path string, info os.FileInfo) bool {
return strings.HasSuffix(path, ".go")
},
}
err := utils.TraverseDirectory(dirParams)
if err != nil {
fmt.Printf("An error occurred: %s\n", err)
}
}
var concatenatedContent []byte
for _, myFilePath := range files {
fileInfo, _ := os.Stat(myFilePath)
if !fileInfo.IsDir() {
content, err := os.ReadFile(myFilePath)
if err != nil {
fmt.Println("Error reading file:", err)
continue
}
fileName := utils.RemovePathPrefix(myFilePath, folderPaths)
concatenatedContent = append(concatenatedContent, []byte(fmt.Sprintf("# FileName: %s \n\n", fileName))...)
concatenatedContent = append(concatenatedContent, content...)
}
}
outputFilePath := "./output.md" // Change this to the desired output file path
err := os.WriteFile(outputFilePath, concatenatedContent, 0644)
if err != nil {
fmt.Println("Error writing concatenated content to file:", err)
return
}
fmt.Println("Concatenated content saved to", outputFilePath)
}