Golang determines whether js file exists

Release: 2019-12-24 10:35:46
Original
2399 people have browsed it

Golang determines whether js file exists

go languageTo detect whether the file exists, first create a FileInfo. If no error is reported, then check whether it is a directory through IsDir()

Code As follows:

finfo, err := os.Stat("filename.js") if err != nil { // no such file or dir return } if finfo.IsDir() { // it's a file } else { // it's a directory }
Copy after login

The method for golang to determine whether a file or folder exists is to use the error value returned by the os.Stat() function to determine:

1. If the returned error is nil, explain The file or folder exists

2. If the error type returned is true using os.IsNotExist(), it means the file or folder does not exist

3. If the error type returned is other types , then you are not sure whether it exists.

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

The above is the detailed content of Golang determines whether js file exists. 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!