Home  >  Article  >  Backend Development  >  Golang determines whether js file exists

Golang determines whether js file exists

尚
Original
2019-12-24 10:35:462414browse

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
}

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 the golang tutorial column 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!

Statement:
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