Created
February 23, 2016 21:01
-
-
Save delputnam/bc27fdd9456577713a3f to your computer and use it in GitHub Desktop.
Check for existence of file using golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if _, err := os.Stat("/path/to/file/or/dir"); os.IsNotExist(err) { | |
// /path/to/file/or/dir does not exist | |
} | |
if _, err := os.Stat("/path/to/file/or/dir"); err == nil { | |
// /path/to/file/or/dir exists | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment