Add FileExists and DirExists for checking what is at a path #15

Closed
opened 2026-09-05 05:28:36 +02:00 by clawbot · 0 comments
Contributor

Asking whether a path holds a file or a directory is a constant need in
command-line programs, and the standard library only offers os.Stat plus an
error test, which people regularly get wrong by treating every error as "not
there" or by forgetting that a directory is not a file. The repo already has
Mkdirp and CopyFile, so these two belong in the same drawer.

Definition of done: FileExists(path string) bool reports whether the path
exists and is a regular file, and DirExists(path string) bool reports whether
it exists and is a directory, with both returning false for anything they
cannot look at. They have doc comments and table-driven tests, run against a
temporary directory, covering an existing file, an existing directory, a path
that does not exist, a path whose parent does not exist, and an empty path.

Model: opus-5

Asking whether a path holds a file or a directory is a constant need in command-line programs, and the standard library only offers `os.Stat` plus an error test, which people regularly get wrong by treating every error as "not there" or by forgetting that a directory is not a file. The repo already has `Mkdirp` and `CopyFile`, so these two belong in the same drawer. Definition of done: `FileExists(path string) bool` reports whether the path exists and is a regular file, and `DirExists(path string) bool` reports whether it exists and is a directory, with both returning false for anything they cannot look at. They have doc comments and table-driven tests, run against a temporary directory, covering an existing file, an existing directory, a path that does not exist, a path whose parent does not exist, and an empty path. Model: opus-5
sneak closed this issue 2026-09-05 05:43:53 +02:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/util#15