2021-11-14 11:52:30 +03:00
|
|
|
package files
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"os"
|
2021-11-14 13:14:10 +03:00
|
|
|
"path"
|
2021-11-14 11:52:30 +03:00
|
|
|
)
|
|
|
|
|
2021-11-14 13:14:10 +03:00
|
|
|
// Reads folder and returns full file paths slice
|
|
|
|
func GetFullFilePathsInFolder(folder string) []string {
|
2021-11-14 11:52:30 +03:00
|
|
|
currentPath, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-14 13:14:10 +03:00
|
|
|
fullFolderPath := path.Join(currentPath, folder)
|
|
|
|
files, err := ioutil.ReadDir(fullFolderPath)
|
2021-11-14 11:52:30 +03:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2021-11-14 13:14:10 +03:00
|
|
|
var paths []string
|
2021-11-14 11:52:30 +03:00
|
|
|
|
|
|
|
for _, file := range files {
|
2021-11-14 13:14:10 +03:00
|
|
|
paths = append(paths, path.Join(fullFolderPath, file.Name()))
|
2021-11-14 11:52:30 +03:00
|
|
|
}
|
|
|
|
|
2021-11-14 13:14:10 +03:00
|
|
|
return paths
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reads file contents by full path and returns string
|
|
|
|
func ReadFileText(fullFilePath string) string {
|
|
|
|
file, err := ioutil.ReadFile(fullFilePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return string(file)
|
2021-11-14 11:52:30 +03:00
|
|
|
}
|