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
672 B

  1. package Filesystem
  2. import (
  3. "io/fs"
  4. "io/ioutil"
  5. "os"
  6. "path/filepath"
  7. )
  8. func CopyFile(src, dest string) error {
  9. var (
  10. input []byte
  11. fileInfo fs.FileInfo
  12. srcBasePath string
  13. destBasePath string
  14. e error
  15. )
  16. srcBasePath = filepath.Dir(src)
  17. destBasePath = filepath.Dir(dest)
  18. fileInfo, e = os.Stat(srcBasePath)
  19. if e != nil {
  20. return e
  21. }
  22. e = os.MkdirAll(destBasePath, fileInfo.Mode())
  23. if e != nil {
  24. return e
  25. }
  26. fileInfo, e = os.Stat(src)
  27. if e != nil {
  28. return e
  29. }
  30. input, e = ioutil.ReadFile(src)
  31. if e != nil {
  32. return e
  33. }
  34. e = ioutil.WriteFile(dest, input, fileInfo.Mode())
  35. if e != nil {
  36. return e
  37. }
  38. return nil
  39. }