Refine some codes of make directory.

This commit is contained in:
zicla
2019-03-01 02:25:32 +08:00
parent daa4a3e7b8
commit 431ef6accc
5 changed files with 57 additions and 14 deletions

View File

@ -58,6 +58,7 @@ func MakeDirAll(dirPath string) string {
panic("判断文件是否存在时出错!")
}
if !exists {
//TODO:文件权限需要进一步考虑
err = os.MkdirAll(dirPath, 0777)
if err != nil {
panic("创建文件夹时出错!")
@ -67,6 +68,24 @@ func MakeDirAll(dirPath string) string {
return dirPath
}
//移除某个文件夹。 例如:/var/www/matter => /var/www
func RemoveDirectory(dirPath string) string {
exists, err := PathExists(dirPath)
if err != nil {
panic("判断文件是否存在时出错!")
}
if exists {
err = os.Remove(dirPath)
if err != nil {
panic("删除文件夹时出错!")
}
}
return dirPath
}
//获取配置文件存放的位置
//例如C:\Users\lishuang\AppData\Local\Temp/conf
func GetConfPath() string {
@ -115,7 +134,7 @@ func GetUserFilePath(username string, cache bool) (string, string) {
datePath := now.Format("2006-01-02")
//毫秒时间戳
timestamp := now.UnixNano() / 1e6
//如果是缓存文件夹那么统一放在cache这个文件夹下面
if cache {
datePath = fmt.Sprintf("cache/%s", datePath)