Automatically create the entry directory when printing the entry list (if it does not already exist)

This commit is contained in:
2024-01-17 23:00:16 -05:00
parent 95eff67340
commit cd78442257
+14
View File
@@ -3,6 +3,7 @@ package main
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"strings"
)
@@ -49,6 +50,19 @@ func EntryListGen() {
_ = filepath.WalkDir(EntryRoot,
func(fullPath string, entry fs.DirEntry, err error) error {
// check for errors encountered while walking directory
if err != nil {
// create EntryRoot if the error is the result of it not existing on the system
if err.Error() == "lstat "+EntryRoot+": no such file or directory" {
_ = os.Mkdir(EntryRoot, 0700)
} else {
// otherwise, print the source of the error
fmt.Print("\n\n\033[38;5;9mAn unexpected error occurred while generating the entry list: " + err.Error() + "\033[0m")
}
// quit walking EntryRoot and return nil to allow the program to continue
return nil
}
// trim root path from each path before storing
trimmedPath := fullPath[RootLength:]