다른 디렉토리의 다른 파일과 하위 디렉토리에있는 파일을 루비를 사용하여 일치 시키려고합니다.ruby에서 bsearch와 find의 차이점
tree .
.
├── src
│ ├── lol
│ │ └── toto
│ └── lolilolpouet
│ └── tutu
│ └── tata
├── test
│ ├── tata
│ └── toto
└── test.rb
내 루비 코드는 다음과 같습니다 :
require 'find'
src_dir_files = []
Find.find('./src') do |file|
src_dir_files << file
puts "found #{file}"
end
Dir.foreach('./test') do |file|
next if file == '.' or file == '..'
puts "search for /#{file}"
res = src_dir_files.bsearch{|s| s.end_with? "/#{file}"}
puts "Found :#{res}"
end
출력은 다음과 같습니다
나는이 파일 아키텍처를 사용하여 작은 테스트를 만들기 위해 노력 토토found ./src
found ./src/lol
found ./src/lol/toto
found ./src/lolilolpouet
found ./src/lolilolpouet/tutu
found ./src/lolilolpouet/tutu/tata
search for /tata
Found :./src/lolilolpouet/tutu/tata
search for /toto
Found :
검색 결과를 반환하지 않습니다. 이유가 무엇이며 어떻게 고칠 수 있습니까?
편집 : 위의 코드는 bsearch를 find로 바꾸면 의도 한대로 동작합니다. 저에게이 두 가지 방법의 차이점을 설명 할 수 있습니까?
나는 당신이 그것을 시도하려는 경우 TGZ을 업로드 : 나는 다음과 같이 할 것
원래 질문을 변경 한 것 같습니다 – bjhaid