how to calculate file number in a folder

L

Li Chen

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
 
S

snacktime

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,215
Messages
2,571,113
Members
47,713
Latest member
LeliaB1379

Latest Threads

Top