Add File.exists?
This commit is contained in:
+15
@@ -28,6 +28,21 @@ defmodule File do
|
||||
FL.is_dir(directory)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns if `file` exists
|
||||
|
||||
## Examples
|
||||
|
||||
File.exists?("/tmp")
|
||||
#=> true
|
||||
|
||||
File.exists?("missing.txt")
|
||||
#=> false
|
||||
"""
|
||||
def exists?(filename) do
|
||||
is_tuple(FL.last_modified(filename))
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the last component of the `filename` or the file
|
||||
name itself if it does not contain any directory separators.
|
||||
|
||||
@@ -32,6 +32,14 @@ defmodule FileTest do
|
||||
refute File.regular?("#{__FILE__}.unknown")
|
||||
end
|
||||
|
||||
test :exists do
|
||||
assert File.exists?(__FILE__)
|
||||
assert File.exists?(File.expand_path("../fixtures/foo.txt", __FILE__))
|
||||
|
||||
refute File.exists?("fixtures/missing.txt")
|
||||
refute File.exists?("_missing.txt")
|
||||
end
|
||||
|
||||
test :basename_with_binary do
|
||||
assert File.basename("foo") == "foo"
|
||||
assert File.basename("/foo/bar") == "bar"
|
||||
|
||||
Reference in New Issue
Block a user