func parseFolder(folder string) string { dir, err := os.Open(folder) lib.CheckErr(err) defer dir.Close() fi, err := dir.Stat() lib.CheckErr(err) filenames := make([]string, 0) if fi.IsDir() { fis, err := dir.Readdir(-1) // -1 means return all FileInfos lib.CheckErr(err) for _, fileinfo := range fis { if !fileinfo.IsDir() { filenames = append(filenames, fileinfo.Name()) } } } log.Println("Parsing Files: ", filenames) // Table of Contents result := "# Table of Contents\n\n| Data Source | Description File | Sample File | Logic File |\n|---|---|---|\n" for _, file := range filenames { // Only process .txt and .csv files if lib.FileExtension(file) == ".txt" || lib.FileExtension(file) == ".csv" { result += "|[" + lib.FileLessExtension(file) + "](#" + lib.FileLessExtension(file) + ") |" result += lib.ParseDescFile(folder, file) + " | " // adds filename as Sample File field result += file + " |" // adds logic file if it exists result += lib.FileLessExtension(file) + ".logic |\n" } } result += "\n" // Parse Files for _, file := range filenames { if lib.FileExtension(file) == ".txt" { // Parse the data file log.Println(folder + "/" + file) result += lib.ParseDatafile(folder, file, "t", 1) // Parse the logic file log.Println(folder + "/" + file) result += lib.ParseLogic(folder, file) } if lib.FileExtension(file) == ".csv" { // Parse the data file log.Println(folder + "/" + file) result += lib.ParseDatafile(folder, file, "c", 1) // Parse the logic file log.Println(folder + "/" + file) result += lib.ParseLogic(folder, file) } } return result }
func initFolder(folder string) { //opens the folder and defers closing the folder until this function exits dir, err := os.Open(folder) lib.CheckErr(err) defer dir.Close() // from the folder object created, return all the files at the top level fi, err := dir.Stat() lib.CheckErr(err) filenames := make([]string, 0) if fi.IsDir() { fis, err := dir.Readdir(-1) // -1 means return all FileInfos lib.CheckErr(err) for _, fileinfo := range fis { if !fileinfo.IsDir() { filenames = append(filenames, fileinfo.Name()) } } } // Print to screen/log files that were found log.Println("Initializing Folder: ", folder) // Table of Contents for _, file := range filenames { // Only process .txt and .csv files if lib.FileExtension(file) == ".txt" || lib.FileExtension(file) == ".csv" { // adds description file if it does not exist if lib.Exists(folder + "/" + lib.FileLessExtension(file) + ".desc") { log.Println(lib.FileLessExtension(file) + ".desc" + " found.") } else { // Create a logic file where one doesn't exist newLogicFile, _ := os.Create(folder + "/" + lib.FileLessExtension(file) + ".desc") newLogicFile.WriteString("// This is a description file, it allows you to document your analysis of specific files\n") log.Println("No Description File, One Created: " + newLogicFile.Name()) } // adds logic file if it does not exist if lib.Exists(folder + "/" + lib.FileLessExtension(file) + ".logic") { log.Println(lib.FileLessExtension(file) + ".logic" + " found.") } else { log.Println(lib.FileLessExtension(file) + ".logic" + " not found! Template file created") newLogicFile, _ := os.Create(folder + "/" + lib.FileLessExtension(file) + ".logic") newLogicFile.WriteString("// Template file created, these are comments\n") newLogicFile.WriteString("# Sample Flow Name\n") newLogicFile.WriteString("! Sample Operator Name\n") newLogicFile.WriteString("- X + Y = Z Sample Calculation for Operator\n") } } } return }