MCPcopy
hub / github.com/bitfield/script / IfExists

Function IfExists

script.go:126–132  ·  view source on GitHub ↗

IfExists tests whether path exists, and creates a pipe whose error status reflects the result. If the file doesn't exist, the pipe's error status will be set, and if the file does exist, the pipe will have no error status. This can be used to do some operation only if a given file exists: IfExists

(path string)

Source from the content-addressed store, hash-verified

124//
125// IfExists("/foo/bar").Exec("/usr/bin/something")
126func IfExists(path string) *Pipe {
127 _, err := os.Stat(path)
128 if err != nil {
129 return NewPipe().WithError(err)
130 }
131 return NewPipe()
132}
133
134// ListFiles creates a pipe containing the files or directories specified by
135// path, one per line. path can be a glob expression, as for [filepath.Match].

Calls 2

NewPipeFunction · 0.85
WithErrorMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…