mirror of https://github.com/Xhofe/alist
31 lines
568 B
Go
31 lines
568 B
Go
package utils
|
||
|
||
import (
|
||
log "github.com/sirupsen/logrus"
|
||
"os"
|
||
"path/filepath"
|
||
)
|
||
|
||
// Exists determine whether the file exists
|
||
func Exists(name string) bool {
|
||
if _, err := os.Stat(name); err != nil {
|
||
if os.IsNotExist(err) {
|
||
return false
|
||
}
|
||
}
|
||
return true
|
||
}
|
||
|
||
// CreatNestedFile create nested file
|
||
func CreatNestedFile(path string) (*os.File, error) {
|
||
basePath := filepath.Dir(path)
|
||
if !Exists(basePath) {
|
||
err := os.MkdirAll(basePath, 0700)
|
||
if err != nil {
|
||
log.Errorf("can't create foler,%s", err)
|
||
return nil, err
|
||
}
|
||
}
|
||
return os.Create(path)
|
||
}
|