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

Golang determines whether js file exists

Release: 2019-12-24 10:35:46
Original
2593 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 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!

Related labels:
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 Issues
How to choose golang web mvc framework
From 1970-01-01 08:00:00
0
0
0
Is it necessary to use nginx when using golang?
From 1970-01-01 08:00:00
0
0
0
golang - vim plug-in to write go
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template