I have a large program in Ruby that's being distributed over several projects. The only problem is the other several projects all have separate members on them that have their own way of coding, and the program is set up to be alongside a specific path, which was for the first project that I used it w/. I've had so many errors to correct that were simply mistaken paths. What I want to do now is scan an entire project for an individual directory (as the program's overhead directory is constant in every instance of its usage) and then set the path to that directory. To keep things simplistic, let's say it's w/ a Rails project, so Rails.root
can be the overhead, and the directory to search for is myawesomedir
. Any help is greatly appreciated!
Asked
Active
Viewed 44 times
0

T145
- 1,415
- 1
- 13
- 33
-
So what do you expect as an answer here? I have no clue what you want. – phoet Dec 18 '13 at 14:21
-
Should be fairly straight forward. "What I want to do now is scan an entire project for an individual directory (as the program's overhead directory is constant in every instance of its usage) and then set the path to that directory." – T145 Dec 18 '13 at 14:22
-
You are not providing any code, no examples and just prose. This topic is not suited for SO. – phoet Dec 18 '13 at 14:23
-
What code is needed to provide? If the purpose I desire is unknown to me, how am I supposed to provide towards it? – T145 Dec 18 '13 at 14:25
-
Yeah, like I said, your question is not suited for SO. – phoet Dec 18 '13 at 14:26
-
What is SO? Please be specific. – T145 Dec 18 '13 at 14:27
-
1It is very much suited for StackOverflow, because it's a programming related question. Many, many people have posted questions that don't include code examples. E.g. http://stackoverflow.com/questions/735073/best-way-to-require-all-files-from-a-directory-in-ruby?rq=1 – T145 Dec 18 '13 at 14:32
1 Answers
1
You can use the find stdlib:
require 'find'
Find.find(Rails.root) do |path|
if File.basename(path) == 'myawesomedir'
Dir.chdir path
break
end
end

Max
- 21,123
- 5
- 49
- 71
-
Is the break statement necessary? Also, what would I do if I wanted to check every directory w/in `Rails.root` for that string? – T145 Dec 18 '13 at 16:04
-
find is for searching a directory and all of its subdirectories. The `break` is not necessary, but once you've found the directory to `chdir` to, there's no need to continue searching. If the target directory cannot be inside a subdirectory, you don't need to use find. Just use `Dir.entries(Rails.root)`. – Max Dec 18 '13 at 16:38