Allow multiple directories, Rename module
This commit is contained in:
parent
e4774d0d6a
commit
41504f2ea1
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
pdf
|
||||
PDFIndexer
|
||||
index.json
|
||||
|
2
go.mod
2
go.mod
@ -1,4 +1,4 @@
|
||||
module cringe-studios.com/pdf
|
||||
module git.cringe-studios.com/CringeStudios/PDFIndexer
|
||||
|
||||
go 1.20
|
||||
|
||||
|
16
main.go
16
main.go
@ -13,15 +13,16 @@ import (
|
||||
"code.sajari.com/docconv"
|
||||
)
|
||||
|
||||
var fileFormats = []string{".pdf", ".jpg", ".png", ".txt", ".docx", ".doc", ".tif"}
|
||||
var fileFormats = []string{".pdf", ".jpg", ".png", ".txt", ".docx", ".doc", ".tif", "tiff"}
|
||||
|
||||
func buildIndex(dir string, old map[string]string) (map[string]string, error) {
|
||||
func buildIndex(dirs []string, old map[string]string) (map[string]string, error) {
|
||||
var index = old
|
||||
|
||||
if index == nil {
|
||||
index = make(map[string]string)
|
||||
}
|
||||
|
||||
for _, dir := range dirs {
|
||||
err := filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@ -63,6 +64,7 @@ func buildIndex(dir string, old map[string]string) (map[string]string, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return index, nil
|
||||
}
|
||||
@ -72,13 +74,13 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if len(flag.Args()) != 2 {
|
||||
fmt.Println("Usage:", os.Args[0], "<directory> <destination file>")
|
||||
if len(flag.Args()) < 2 {
|
||||
fmt.Println("Usage:", os.Args[0], "<destination file> <directory> [directories...]")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
directory := flag.Arg(0)
|
||||
indexFile := flag.Arg(1)
|
||||
indexFile := flag.Arg(0)
|
||||
directories := flag.Args()[1:]
|
||||
var oldIndex = make(map[string]string)
|
||||
|
||||
if !*force {
|
||||
@ -97,7 +99,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
index, err := buildIndex(directory, oldIndex)
|
||||
index, err := buildIndex(directories, oldIndex)
|
||||
if err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user