ruby - Dir.glob recursive file search and stop at occurence and back up a directory -


i want dynamically through possibly many subfolder file. file few folders deep, has done recursively.

but dir.glob stop @ first occurence, , not continue going through other folders. how accomplish this?

this code right now:

def find_installs   installs = []   glob_dir = @config[:install_folders]   dir.glob("#{glob_dir}**/install_file.md").each |install_file|     installs << file.dirname(install_file).gsub(glob_dir, "")   end    installs end 

is there class use provides functionality?

by way, code has run on ruby 1.9.3

required lib find.

i have created folder structure follows :-

/folder1/ |- folder2/      |-folder21/         |-a.txt      |-a.txt |- folder3/      |-folder31/         |-a.txt      |-a.txt 

now write code below meet op's need :-

require 'find'  path_find = '/home/kirti/workspace/folder1'  find.find(path_find) |path|   if filetest.directory?(path)     unless dir["#{path}/a.txt"].empty?       p "#{path}/a.txt"       find.prune # don't further directory.     else       next     end   else     # nothing   end end # >> "/home/kirti/workspace/folder1/folder2/a.txt" # >> "/home/kirti/workspace/folder1/folder3/a.txt" 

you can see folder21 contains a.txt file, folder2 contains a.txt, no search made sub-directory folder21. same explanation applicable folder3 , sub-directory folder31.


Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -