|
- package main
-
- import (
- "fmt"
- "io"
- "os"
- "path/filepath"
- "strings"
- )
-
- func fileNameWithoutExtTrimSuffix(fileName string) string {
- return strings.TrimSuffix(fileName, filepath.Ext(fileName))
- }
-
- func copyFile(src, dst string) (int64, error) {
- sourceFileStat, err := os.Stat(src)
- if err != nil {
- return 0, err
- }
-
- if !sourceFileStat.Mode().IsRegular() {
- return 0, fmt.Errorf("%s is not a regular file", src)
- }
-
- source, err := os.Open(src)
- if err != nil {
- return 0, err
- }
- defer source.Close()
-
- destination, err := os.Create(dst)
- if err != nil {
- return 0, err
- }
- defer destination.Close()
- nBytes, err := io.Copy(destination, source)
- return nBytes, err
- }
|