HI All
I am trying to scan .txt files in the folder and make it one string line when finish the scanning file.
Here with i have attach the coding.Could you please help me
package main
import (
“log”
“os”
“bufio”
“io/ioutil”
“go/scanner”
“fmt”
)
func ReadFiles(locationPath string) (string,error) {
folder, err := ioutil.ReadDir(locationPath)
if err != nil {
log.Fatal(err)
//return nil,err
}
var lines string
for _, f := range folder {
file, err := os.Open(locationPath+f.Name())
if err != nil {
log.Fatal(err)
//return nil,err
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
S:= scanner.Text()
lines = lines+","+S
}
fmt.Println(lines)
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
return lines,scanner.Error{}
}
func main() {
var locationPath =“E:/4gproject/”
ReadFiles(locationPath)
}
my tex files are
file 1
OHM_1577_1438Cafe1
201599 MB
jun/01/2019 09:04:08
201599,0,42760,44,49,131172
10w5d03:45:12
file 2
cafe 2
223741 MB
jul/16/2019 16:03:31
223741,0,22364,231,161,180228
6w10:00:13
my out put is like
cafe1 ,362751 MB ,jul/16/2019 18:04:56 ,362751,1518,131146,217,128,171076 ,3w1d22:20:16
cafe1 ,362751 MB ,jul/16/2019 18:04:56 ,362751,1518,131146,217,128,171076 ,3w1d22:20:16,cafe2 ,223741 MB ,jul/16/2019 16:03:31 ,223741,0,22364,231,161,180228 ,6w10:00:13
I am expecting out put like
cafe1 ,362751 MB ,jul/16/2019 18:04:56 ,362751,1518,131146,217,128,171076 ,3w1d22:20:16
adn new line
,cafe2 ,223741 MB ,jul/16/2019 16:03:31 ,223741,0,22364,231,161,180228 ,6w10:00:13
please help me
thanks
Sudesh