CopyFile copy file
(source string, dest string)
| 8 | |
| 9 | // CopyFile copy file |
| 10 | func CopyFile(source string, dest string) (err error) { |
| 11 | sourcefile, err := os.Open(source) |
| 12 | if err != nil { |
| 13 | return err |
| 14 | } |
| 15 | |
| 16 | defer sourcefile.Close() |
| 17 | |
| 18 | destfile, err := os.Create(dest) |
| 19 | if err != nil { |
| 20 | return err |
| 21 | } |
| 22 | |
| 23 | defer destfile.Close() |
| 24 | |
| 25 | _, err = io.Copy(destfile, sourcefile) |
| 26 | if err == nil { |
| 27 | sourceinfo, err := os.Stat(source) |
| 28 | if err != nil { |
| 29 | _ = os.Chmod(dest, sourceinfo.Mode()) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return |
| 34 | } |
| 35 | |
| 36 | // CopyDir recursive copy of directory |
| 37 | func CopyDir(source string, dest string) (err error) { |