1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 15:24:42 -05:00
sub2clash/common/mkdir.go

34 lines
680 B
Go
Raw Normal View History

package common
import (
"errors"
"os"
)
func MKDir(dir string) error {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.MkdirAll(dir, os.ModePerm)
if err != nil {
return err
}
}
return nil
}
func MkEssentialDir() error {
if err := MKDir("subs"); err != nil {
return errors.New("create subs dir failed" + err.Error())
}
if err := MKDir("templates"); err != nil {
return errors.New("create templates dir failed" + err.Error())
}
if err := MKDir("logs"); err != nil {
return errors.New("create logs dir failed" + err.Error())
}
if err := MKDir("data"); err != nil {
return errors.New("create data dir failed" + err.Error())
}
return nil
}