# How to calculate file number in a folder

**URL:** <https://www.ruby-forum.com/t/how-to-calculate-file-number-in-a-folder/73046>\
**Category:** Ruby\
**Created:** [October 20, 2006, 9:07pm UTC](https://www.ruby-forum.com/t/how-to-calculate-file-number-in-a-folder/73046 "2006-10-20T21:07:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 20, 2006, 9:07pm UTC](https://www.ruby-forum.com/t/how-to-calculate-file-number-in-a-folder/73046/1 "2006-10-20T21:07:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alex-osu3](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/13edae/32.png) [@alex-osu3](https://www.ruby-forum.com/u/alex-osu3)\
**Post date:** [October 20, 2006, 10:25pm UTC](https://www.ruby-forum.com/t/how-to-calculate-file-number-in-a-folder/73046/2 "2006-10-20T22:25:24Z")

</div>

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
