39 lines
853 B
Go
39 lines
853 B
Go
package l_export_async
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func Test_Merge(t *testing.T) {
|
|
path := "/tmp/f63b2047-dd7b-11f0-b1a8-00155d5ef0f92960656377/csv/"
|
|
outputDir := "/tmp/f63b2047-dd7b-11f0-b1a8-00155d5ef0f92960656377/xlsx/aaa.xlsx"
|
|
csvFiles, err := listFiles(path)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
m := NewMerge(
|
|
Reader{Files: csvFiles, Index: len(csvFiles) - 1},
|
|
Writer{File: outputDir, Limit: 30000, BufferSize: 3000},
|
|
NewLogPrint(nil),
|
|
)
|
|
err = m.Merge()
|
|
t.Log(err)
|
|
}
|
|
|
|
func listFiles(dirPath string) ([]string, error) {
|
|
entries, err := os.ReadDir(dirPath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read directory: %w", err)
|
|
}
|
|
|
|
var files []string
|
|
for _, entry := range entries {
|
|
if !entry.IsDir() { // 只添加文件(排除子目录)
|
|
files = append(files, dirPath+entry.Name())
|
|
}
|
|
}
|
|
return files, nil
|
|
}
|