How to determine whether a directory is in golang

Release: 2020-01-13 09:56:58
Original
6424 people have browsed it

How to determine whether a directory is in golang

How to determine whether it is a file or a directory in golang:

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() }
Copy after login

os.path.isdir() is used to determine whether the object is a directory. Returns true if the specified file is a directory, false otherwise.

For more golang knowledge, please pay attention to thegolang tutorialcolumn on the PHP Chinese website.

The above is the detailed content of How to determine whether a directory is in golang. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!