Dir with patterns : Dir « File Directory « Ruby






Dir with patterns


Dir['*.data']       # Files with the "data" extension
Dir['ruby.*']       # Any filename beginning with "ruby."
Dir['?']            # Any single-character filename
Dir['*.[ch]']       # Any file that ends with .c or .h
Dir['*.{java,rb}']  # Any file that ends with .java or .rb
Dir['*/*.rb']       # Any Ruby program in any direct sub-directory
Dir['**/*.rb']      # Any Ruby program in any descendant directory

 








Related examples in the same category

1.more concise way of getting directory listings is by using Dir's class array method
2.a little more platform independent:
3.Find all the "regular" files and subdirectories in mydir.
4.Find all the .rb files in mydir
5.Dir["mydir/**/*"]
6.Dir["mydir/**/*file*"]
7.Regex-style character classes
8.Match any of the given strings
9.Single-character wildcards