From: Li Chen Date: 2006-10-21T05:09:14+09:00 Subject: Re: how to calculate file number in a folder > > Here's one way. (There are many, I'm sure.) > > #Find all the entries in a directory > irb(main):009:0> Dir[ 'c:/ruby/*' ] > > # Find select just the ones that are files: > irb(main):010:0> Dir[ 'c:/ruby/*' ].select{ |path| File.file?( path ) } > > # Find the length of that list > irb(main):011:0> Dir[ 'c:/ruby/*' ].select{ |path| File.file?( path ) > }.length > => 8 > > > One other way: > > file_count = 0 > Dir[ 'c:/ruby/*' ].each{ |path| > if File.file?( path ) > # Do something to the file > file_count += 1 > end > } Thank you, Li -- Posted via http://www.ruby-forum.com/.