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.

50 lines
696 B

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
}