diff options
| author | Jeff Carr <[email protected]> | 2019-06-14 19:05:17 -0700 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2019-06-14 19:05:17 -0700 |
| commit | 8d1122b534a7d518b2df8baecd580ff337fa8f21 (patch) | |
| tree | c5245c8ccbc52b1f34fbac775e386b471cffc345 /shell.go | |
| parent | 2dc091f5bc0cb901a19b751e2c0641e5b2a26e75 (diff) | |
add shell.Cat()
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'shell.go')
| -rw-r--r-- | shell.go | 20 |
1 files changed, 15 insertions, 5 deletions
@@ -8,7 +8,7 @@ import "os/exec" import "bufio" import "bytes" import "io" -// import "io/ioutil" +import "io/ioutil" import "github.com/davecgh/go-spew/spew" import "github.com/svent/go-nbreader" @@ -268,20 +268,30 @@ func Exec(cmdline string) { os.Exit(0) } -// return true if the filename exists +// return true if the filename exists (cross-platform) func Exists(filename string) bool { - _, err := os.Stat(filename) + _, err := os.Stat(Path(filename)) if os.IsNotExist(err) { return false } return true } -// return true if the filename exists +// return true if the filename exists (cross-platform) func Dir(dirname string) bool { - info, err := os.Stat(dirname) + info, err := os.Stat(Path(dirname)) if os.IsNotExist(err) { return false } return info.IsDir() } + +// Cat a file into a string +func Cat(filename string) string { + buffer, err := ioutil.ReadFile(Path(filename)) + // log.Println("buffer =", string(buffer)) + if err != nil { + return "" + } + return Chomp(buffer) +} |
