Ruby/File Directory/Dir.entries

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Dir.entries contains all the entries found in a directory

# including files, hidden files, and other directories, one array element per entry. 
# I"ll apply Array"s each method to the output of entries:
Dir.entries( "/usr/local/src/ruby-1.8.6" ).each { |e| puts e }



get a list of the files and directories within a specific directory using Dir.entries:

puts Dir.entries("/usr/bin").join(" ")



Listing A Directory

p Dir.entries("mydir")
Dir.foreach("mydir") { |x| puts x if x != "." && x != ".."}