-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (57 loc) · 1.32 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
)
func readFileNames(filename string) []string {
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
var filenames []string
for scanner.Scan() {
filenames = append(filenames, scanner.Text())
}
return filenames
}
func main() {
var files []string
root := "."
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
panic(err)
}
var searchFilenames = readFileNames("data.txt")
fmt.Println(searchFilenames)
var existingfilenames []string
for _, file := range files {
var reducedFilename = filepath.Base(file)
existingfilenames = append(existingfilenames, reducedFilename)
}
fmt.Println("--------------")
fmt.Println(existingfilenames)
// search for files that do not exist in the existing files
var missingfilenames []string
for i := 0; i < len(searchFilenames); i++ {
exists := false
for j := 0; j < len(existingfilenames); j++ {
if searchFilenames[i] == existingfilenames[j] {
exists = true
break
}
}
if !exists {
missingfilenames = append(missingfilenames, searchFilenames[i])
}
}
fmt.Println("######################")
fmt.Println(missingfilenames)
}