1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- package osutil
- import (
- "os"
- )
- func IsFile(path string) bool {
- f, e := os.Stat(path)
- if e != nil {
- return false
- }
- return !f.IsDir()
- }
- func IsDir(dir string) bool {
- f, e := os.Stat(dir)
- if e != nil {
- return false
- }
- return f.IsDir()
- }
- func IsExist(path string) bool {
- _, err := os.Stat(path)
- return err == nil || os.IsExist(err)
- }
- func CurrentUsername() string {
- username := os.Getenv("USER")
- if len(username) > 0 {
- return username
- }
- return os.Getenv("USERNAME")
- }
|