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

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