Sanitize File\exists? + add missing stdlib function #1570
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Right now, we have
exists?
, which works in the following way:exists? "some/path"
- will return true if the path exists and points to a file, but false if the path exists but points to a directory or anything else (or: ofc, if the aforementioned path doesn't exist altogether)exists?.directory "some/path"
- will return true if the path exists and point to a directory, but false if the path exists but points to a file or anything else (or: ofc, if the aforementioned path doesn't exist altogether)That sounds a bit confusing. (See here: https://discord.com/channels/765519132186640445/829324913097048065/1208304920957157386)
Basically, if we want to check if a given path is a directory, we'd have to do
exists?.directory
- which is correct, although it's not ultra-intuitive.What this PR is going to do is:
exists?
returns true if the path exists (be it a file, a directory or whatever) and false otherwisefile?
&directory?
predicate/function to check if a given path is a file or directory, respectively. (We could perhaps add anothersymlink?
function, since it's a thing and Nim allows us to do this quite easily 😉 )Type of change