Help us understand the problem. What is going on with this article?

Railsの特定のディレクトリ以下のファイルを探る

More than 1 year has passed since last update.

再帰的に特定のディレクトリ以下のファイルパスを取得したい時は、
Dirクラスを使ってパスを取得する。

Railsで呼び出す場合は、Rails.rootを使うと実行しているOSでRailsが動いている絶対パスを取得できるので、本番環境や開発環境を指揮する必要がなくて便利

実行例

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

=> "/var/app/models/user.rb"
"/var/app/models/owner.rb"
"/var/app/models/blog"
"/var/app/models/blogs/comment.rb"
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした