-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (55 loc) · 956 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"path/filepath"
)
var verbose bool
var inputDir = "/mydata/input"
var outputDir = "/mydata/output"
func main() {
flag.BoolVar(&verbose, "v", true, "verbose output")
flag.Parse()
print("Copying input to output")
inputFiles, err := ioutil.ReadDir(inputDir)
if err != nil {
log.Fatal(err)
}
for _, fi := range inputFiles {
src := filepath.Join(inputDir, fi.Name())
dst := filepath.Join(outputDir, fi.Name())
err := copyFile(src, dst)
if err != nil {
log.Fatal(err)
}
}
print("Done")
}
func copyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
}
defer in.Close()
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, in)
cerr := out.Close()
if err != nil {
return err
}
return cerr
}
func print(v ...interface{}) {
if !verbose {
return
}
fmt.Println(v...)
}