Go provides an
os.File type which represents an open file descriptor and is returned by methods such as os.Open:
file returned here could either be a self-contained file or a directory containing other files. Here’s how to distinguish between the two:
If you want to check this information without opening the file, you can use
os.Stat() and pass the path to the file.
If you have to check for this often, consider wrapping up the code in function such as the one shown below:
As you can see, determining if a file is a directory or not is pretty straightforward in Go. If you know of any other techniques different to what is posted above, please mention it in the comments.
Thanks for reading, and happy coding!