20 lines
531 B
Go
20 lines
531 B
Go
package mover
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Move moves the file to destDir/destName, creating directories as needed.
|
|
func Move(src, destDir, destName string) (string, error) {
|
|
if err := os.MkdirAll(destDir, 0o755); err != nil {
|
|
return "", fmt.Errorf("mkdir %s: %w", destDir, err)
|
|
}
|
|
destPath := filepath.Join(destDir, destName)
|
|
if err := os.Rename(src, destPath); err != nil {
|
|
return "", fmt.Errorf("rename %s -> %s: %w", src, destPath, err)
|
|
}
|
|
return destPath, nil
|
|
}
|