Skip to content

Instantly share code, notes, and snippets.

@Ethan-Arrowood
Created September 29, 2018 19:39
Show Gist options
  • Save Ethan-Arrowood/9cbeafff8bfe4cfff49018d83564c9d4 to your computer and use it in GitHub Desktop.
Save Ethan-Arrowood/9cbeafff8bfe4cfff49018d83564c9d4 to your computer and use it in GitHub Desktop.
First implementation of a file copy program written in Go
package main
import (
"io/ioutil"
"log"
"os"
)
func fcopy(src, dst string) {
content, err := ioutil.ReadFile(src)
if err != nil {
log.Fatal(err)
}
err = ioutil.WriteFile(dst, content, 0777)
if err != nil {
log.Fatal(err)
}
log.Printf("Successfully copied contens of %s to %s", src, dst)
}
func main() {
if l := len(os.Args); l != 3 {
log.Printf("Usage: fcopy <src file> <dst file>")
} else {
fcopy(os.Args[1], os.Args[2])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment