I have the following directory tree.
- app.rb
- folder/
- one/
- one.rb
- two/
- two.rb
I want to be able to load Ruby files in the folder/ directory, even the ones in the sub-directories. How would I do so?
By default, ls lists just one directory. If you name one or more directories on the command line, ls will list each one. The -R (uppercase R) option lists all subdirectories, recursively.
Substitute dir /A:D. /B /S > FolderList. txt to produce a list of all folders and all subfolders of the directory.
A subfolder is a folder stored inside another folder. Subfolders help you organize your files more completely. Each subfolder should be used to store files related to each other. For example, you might have one folder for files related to a job search.
Jekyll does something similar with its plugins. Something like this should do the trick:
Dir[File.join(".", "**/*.rb")].each do |f|
require f
end
With less code, but still working on Linux, OS X and Windows:
Dir['./**/*.rb'].each{ |f| require f }
The '.'
is needed for Ruby 1.9.2 where the current directory is no longer part of the path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With