mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
31 lines
397 B
Go
31 lines
397 B
Go
|
package files
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
// CopyFile is used to copy a file
|
||
|
func CopyFile(old, new string) error {
|
||
|
// Open the file and create a new one
|
||
|
r, err := os.Open(old)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer r.Close()
|
||
|
|
||
|
w, err := os.Create(new)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
defer w.Close()
|
||
|
|
||
|
// Copy the content
|
||
|
_, err = io.Copy(w, r)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
return nil
|
||
|
}
|