DEV Community


Posted on

Explore files under a specific directory in Rails

If you want to recursively retrieve the file paths under a particular directory, you can use the
Use the Dir class to get the path.

If you want to call it in Rails, you can use Rails.root to get the absolute path where Rails is running on the OS you're running, so you don't have to lead the production or development environment.

execution example

Dir.glob("#{Rails.root}/app/models/**/*") do |f
  p f

=> "/var/app/models/user.rb"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)