# Reading Modified time of a file

**URL:** <https://www.ruby-forum.com/t/reading-modified-time-of-a-file/134843>\
**Category:** Rails\
**Created:** [April 15, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/reading-modified-time-of-a-file/134843 "2008-04-15T15:58:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanth\_u37](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@srikanth\_u37](https://www.ruby-forum.com/u/srikanth_u37)\
**Post date:** [April 15, 2008, 3:58pm UTC](https://www.ruby-forum.com/t/reading-modified-time-of-a-file/134843/1 "2008-04-15T15:58:51Z")

</div>

Hi,

I have to write a method which executes a code block only if the file  
are modified. I am able to do it by reading modified time of the files  
but as the number of files in the directory are more its taking time to  
read each file and verifying the modified time of each file. So please  
help.

Thanks

---

<div class="post-metadata">

**Author:** ![srikanth\_u37](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@srikanth\_u37](https://www.ruby-forum.com/u/srikanth_u37)\
**Post date:** [April 18, 2008, 3:36am UTC](https://www.ruby-forum.com/t/reading-modified-time-of-a-file/134843/2 "2008-04-18T03:36:32Z")

</div>

Perhaps instead of reading each file use the stat function? That  
should be quick enough unless you’re checking hundreds of files.

[http://www.ruby-doc.org/core/classes/File/Stat.html](http://www.ruby-doc.org/core/classes/File/Stat.html)

-Dale
