golang判断是否目录的方法


本文摘自php中文网,作者尚,侵删。

golang中判断是文件还是目录的方法:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

package main

import (

    "os"

        "fmt"

)

func main()  {

    file := "/root/data/testFile.txt"

        fmt.Printf("%s is file: %v\n", file, IsFile(file))

}

// IsFile checks whether the path is a file,

// it returns false when it's a directory or does not exist.

func IsFile(f string) bool {

    fi, e := os.Stat(f)

    if e != nil {

        return false

    }

    return !fi.IsDir()

}

os.path.isdir()用于判断对象是否为一个目录。如果指定文件为目录,则返回 true,否则,返回 false。

更多golang知识请关注PHP中文网golang教程栏目。

以上就是golang判断是否目录的方法的详细内容,更多文章请关注木庄网络博客!!

相关阅读 >>

golang1.4bootstrap无法直接在aarch64编译

通过协程查找数组中元素

golang jwt前端怎么验证

golang 获取当前外网ip/地址/运营商

2021-02-22

go循环队列的实现

golang 为什么高并发

如何编写go中间件

go实战--使用golang开发windows gui桌面程序(lxn/walk)

go 自定义error错误

更多相关阅读请进入《golang》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...