Add File.exists?

This commit is contained in:
Philip Sampaio
2012-05-03 00:46:48 -03:00
parent 39c316d01d
commit 4da2aaaa99
2 changed files with 23 additions and 0 deletions
+15
View File
@@ -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.
+8
View File
@@ -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"