w1100n
This site is best viewed in Google Chrome
1/23/2019 11:11

package main

import (
    "fmt"
    "os"
)

// 判断文件夹是否存在
func PathExists(path string) (bool, error) {
    _, err := os.Stat(path)
    if err == nil {
        return true, nil
    }
    if os.IsNotExist(err) {
        return false, nil
    }
    return false, err
}

func main() {
    _dir := "./gzFiles2"
    exist, err := PathExists(_dir)
    if err != nil {
        fmt.Printf("get dir error![%v]\n", err)
        return
    }

    if exist {
        fmt.Printf("has dir![%v]\n", _dir)
    } else {
        fmt.Printf("no dir![%v]\n", _dir)
        // 创建文件夹
        err := os.Mkdir(_dir, os.ModePerm)
        if err != nil {
            fmt.Printf("mkdir failed![%v]\n", err)
        } else {
            fmt.Printf("mkdir success!\n")
        }
    }
}


作者:robertkun
来源:CSDN
原文:https://blog.csdn.net/robertkun/article/details/78776585
版权声明:本文为博主原创文章,转载请附上博文链接!

<< Previous Posts Newer Posts >>
辽ICP备14012896