I'm used to it./
and../
As the path to access the directory, but today I found that this habit is incorrect when using this function in golang.
But the commonly used commands are not clearly distinguished. and./You can use . or ./ in these commands to reach the directory
ls
cd
Error demonstration
package main import ( "fmt" "io/fs" "os" ) func main() { fsfile := ("./") dir, err := (fsfile, "./") if err != nil { return } for _, file := range dir { (()) } }
If you write this way, the following prompt will appear in err (strangely, when using the 1.22.1rc version, there is no prompt, but in the 1.21.5 version, there will be a prompt without this directory)
readdir ./: invalid argument
This is the correct code
package main import ( "fmt" "io/fs" "os" ) func main() { fsfile := (".") // Use here./or. dir, err := (fsfile, ".") if err != nil { return } for _, file := range dir { (()) } }
After searching, . and .. are representative directories, and ./ and ../ represent directories. This is probably the reason.
This is the end of this article about a comprehensive guide to Golang language. For more related content in golang, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!