Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
concatenate gz files
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
)
func main() {
// dir name
flag.Parse()
dirName := flag.Args()[0]
fmt.Println("File dir: " + dirName)
// read dir
files, err := ioutil.ReadDir(dirName)
if err != nil {
fmt.Println("Dir read ERROR !")
fmt.Println(err)
return
}
// open output file
output := "output.txt.gz"
fp_w, err := os.OpenFile(output, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) // <--- 出力ファイルをオープンします
if err != nil {
return
}
defer fp_w.Close()
// write gz file
for _, file := range files {
fmt.Println("Found gz file: " + file.Name())
gzFile, err := ioutil.ReadFile(dirName + "/" + file.Name()) // <--- gzファイルをオープンします
if err != nil {
return
}
_, err = fp_w.Write(gzFile) // <--- 出力ファイルに書き込みます
if err != nil {
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.