Skip to content

Instantly share code, notes, and snippets.

@suganoo
Created December 13, 2018 04:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suganoo/6ac57b61fe3e6c1984b08f7971201d33 to your computer and use it in GitHub Desktop.
Save suganoo/6ac57b61fe3e6c1984b08f7971201d33 to your computer and use it in GitHub Desktop.
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