go-util/files.go

25 lines
513 B
Go

package util
import (
"fmt"
"os"
"path"
"path/filepath"
"time"
)
func MoveFileToDir(file, dir string) (err error) {
nf := filepath.Join(dir, path.Base(file))
return os.Rename(file, nf)
}
func MkdirTimestamped(dir string) (target string, err error) {
// TODO use filepath join
tf := fmt.Sprintf("%s%c%s%c%s%c%s", dir, filepath.Separator, "2006", filepath.Separator, "01", filepath.Separator, "02")
target = time.Now().Format(tf)
if err = os.MkdirAll(target, 0755); err != nil {
return
}
return
}