How to calculate file number in a folder

Hi folks,

I write a script to find out all the file names and the number of files
in a folder(no other children folder) as following:

Dir.open(‘C:/Ruby/self’).each{
|file|
puts file if file=~/(\w+)|(\d+)/ # remove file .
and …
}

but I am not sure how to calculate the number of file in folder.
Any help will be appreciated.

Li

files = Dir.entries(’/tmp’)
p files.class
files.delete_if {|x| [’.’,’…’].include?(x) } # Get rid of . and …
entries on unix
p files
p files.size

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs