You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
623 B
30 lines
623 B
package util |
|
|
|
import ( |
|
"errors" |
|
"fmt" |
|
"io" |
|
"os" |
|
) |
|
|
|
// opens given files, copies one into another |
|
func CopyFile(srcPath, dstPath string) error { |
|
srcFile, err := os.Open(srcPath) |
|
if err != nil { |
|
return errors.New(fmt.Sprintf("Could not open src file : %s", err)) |
|
} |
|
defer srcFile.Close() |
|
|
|
dstFile, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE, os.ModePerm) |
|
if err != nil { |
|
return errors.New(fmt.Sprintf("Could not open dst file : %s", err)) |
|
} |
|
defer dstFile.Close() |
|
|
|
_, err = io.Copy(dstFile, srcFile) |
|
if err != nil { |
|
return errors.New(fmt.Sprintf("Could not copy file : %s", err)) |
|
} |
|
|
|
return nil |
|
}
|
|
|