File.dir? not working?

iex(11)> lst = File.ls!(Path.expand("./.git"))                             
["HEAD", "hooks", "index", "branches", "refs", "logs", "COMMIT_EDITMSG",
 "objects", "ORIG_HEAD", "config", "description", "info"]
iex(12)> dirs = for x <- lst, File.dir?(x), do: x 
["config"]
iex(13)> lst = for x <- File.ls!(Path.expand("./.git")), do: Path.expand(x)
["/home/alexey/spaces/elixir/ex_procr/HEAD",
 "/home/alexey/spaces/elixir/ex_procr/hooks",
 "/home/alexey/spaces/elixir/ex_procr/index",
 "/home/alexey/spaces/elixir/ex_procr/branches",
 "/home/alexey/spaces/elixir/ex_procr/refs",
 "/home/alexey/spaces/elixir/ex_procr/logs",
 "/home/alexey/spaces/elixir/ex_procr/COMMIT_EDITMSG",
 "/home/alexey/spaces/elixir/ex_procr/objects",
 "/home/alexey/spaces/elixir/ex_procr/ORIG_HEAD",
 "/home/alexey/spaces/elixir/ex_procr/config",
 "/home/alexey/spaces/elixir/ex_procr/description",
 "/home/alexey/spaces/elixir/ex_procr/info"]
iex(14)> dirs = for x <- lst, File.dir?(x), do: x                          
["/home/alexey/spaces/elixir/ex_procr/config"]

Both relative and absolute path cases look equally wrong. Current directory listings are correct:

iex(15)> lst = File.ls!(Path.expand("."))                                  
["README.md", ".git", "pcx", "deps", "mix.lock", "test", "_build", ".gitignore",
 "mix.exs", "config", "lib", ".formatter.exs", "e.vim"]
iex(16)> dirs = for x <- lst, File.dir?(x), do: x
[".git", "deps", "test", "_build", "config", "lib"]

Any ideas?

You are listing the contents of .git and then checking from current working dir without changing or basing on the .git folder. So the config identified here as a folder is probably the config folder of your mix project and the other simply don’t exist.

3 Likes

I’m sorry. Should have paid closer attention, without trusting expand blindly.

No need to be sorry, I know how easy it is to not see the details.