h4cc / Finder

A Elixir module for finding files and directories in a given path.
Apache License 2.0
2 stars 1 forks source link

Is Finder.with_directory_regex working correctly ? #14

Open lowks opened 9 years ago

lowks commented 9 years ago

Here is my tree

 lowks@lowkster ~/src/elixir/Radpath $ tree test
 test
├── fixtures
│   ├── dome.zip
│   ├── file1.txt
│   ├── file2.txt
│   ├── file3.log
│   ├── gogo
│   ├── testdir1
│   │   └── testfile1.txt
│   ├── testdir2
│   │   └── testfile2.txt
│   └── testdir3
│       └── testfile3.txt
├── radpath_test.exs
└── test_helper.exs

I did a regex on directory using this, where the regex should basically return everything in 'test':

iex(1)> result = Finder.new() |>                                 
...(1)>  Finder.with_directory_regex(Regex.compile!("^\/.*")) |> 
...(1)> Finder.only_directories |>
...(1)> Finder.find("test") |>
...(1)> Enum.to_list |>
...(1)> Enum.sort
    []

and using the normal without 'with_directory_regex', here is the output:

iex(2)> result = Finder.new() |> 
...(2)> Finder.only_directories |>
...(2)> Finder.find("test") |>
...(2)> Enum.to_list |>
...(2)> Enum.sort
["test/fixtures", "test/fixtures/gogo", "test/fixtures/testdir1",
 "test/fixtures/testdir2", "test/fixtures/testdir3"]

and

iex(3)> Regex.run(~r/^\/.*/, "/home/lowks/test")
["/home/lowks/test"]

Is there a problem with the way I am using it ?

h4cc commented 9 years ago

My first guess is that the regex "^\/.*" demands a trailing slash, but internally Finder might work with relative paths like "test/...". Dont know for sure ...