package Filesystem
|
|
|
|
import (
|
|
"fmt"
|
|
"io/fs"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
func CopyFile(src, dest string) error {
|
|
var (
|
|
input []byte
|
|
fileInfo fs.FileInfo
|
|
srcBasePath string
|
|
destBasePath string
|
|
e error
|
|
)
|
|
|
|
srcBasePath = filepath.Dir(src)
|
|
destBasePath = filepath.Dir(dest)
|
|
|
|
fileInfo, e = os.Stat(srcBasePath)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
e = os.MkdirAll(destBasePath, fileInfo.Mode())
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
fileInfo, e = os.Stat(src)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
input, e = ioutil.ReadFile(src)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
e = ioutil.WriteFile(dest, input, fileInfo.Mode())
|
|
if e != nil {
|
|
fmt.Println(e)
|
|
return e
|
|
}
|
|
|
|
return nil
|
|
}
|