-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new helper function IsDir (#72)
Showing
2 changed files
with
31 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package file | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
// DeleteDir deletes the directory at the given path. | ||
// It returns nil if the deletion succeeds, or the deletion error otherwise. | ||
// If the directory does not exist, DeleteDir returns nil. | ||
func DeleteDir(path string) error { | ||
if _, err := os.Stat(path); os.IsNotExist(err) { | ||
return nil | ||
} | ||
|
||
return os.Remove(path) | ||
} | ||
|
||
// IsDir returns whether the given path is a directory. If the path does not exist, it returns (false, nil). | ||
// If there is an error checking the path, it returns (false, err). | ||
func IsDir(path string) (bool, error) { | ||
_, err := os.Stat(path) | ||
if err == nil { | ||
return true, nil | ||
} | ||
|
||
if os.IsNotExist(err) { | ||
return false, nil | ||
} | ||
|
||
return false, err | ||
} |
This file contains 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