-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdavey.go
More file actions
52 lines (44 loc) · 953 Bytes
/
Copy pathdavey.go
File metadata and controls
52 lines (44 loc) · 953 Bytes
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
package main
import (
"fmt"
"io/fs"
"log"
"os"
"strings"
"time"
)
func main() {
args := os.Args
var s []string
rootDir := args[1]
fileSystem := os.DirFS(rootDir)
fs.WalkDir(fileSystem, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
log.Fatal(err)
}
if path == "." || strings.Contains(path, "davey") {
fmt.Println(path + " is not required in the output, carrying on.")
} else {
body, err := os.ReadFile(rootDir + path)
if err != nil {
log.Printf("unable to read file: %v", err)
}
s = append(s, string(body))
}
return nil
})
dt := time.Now()
formatted := dt.Format("17052023")
f, err := os.Create(rootDir + formatted + "-davey.log")
if err != nil {
log.Println("Not able to create davey.log file")
}
defer f.Close()
for i := 0; i < len(s); i++ {
_, err := f.WriteString(s[i] + "\n")
if err != nil {
log.Println("unable to write")
}
fmt.Println(s[i])
}
}