Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
特定のディレクトリの下にあるすべてのファイルのリストを取得したいと考えています。Dir.glob はうまく機能しますが、結果をファイル (ディレクトリを除く) だけに制限する方法はないようです。
これが私が今持っているものです:
files = Dir.glob('my_dir/**/*').reject { |f| File.directory?(f) }
これを達成するためのよりエレガントな方法はありますか?
これは実際にはかなり効率的な方法ですが、Find モジュールを使用することもできます。
require 'find' found = [ ] Find.find(base_path) do |path| found << path if (File.file?(path)) end