PackageManager just because
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.

48 lines
702 B

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