# Fast check if files exist

**URL:** <https://www.ruby-forum.com/t/fast-check-if-files-exist/112948>\
**Category:** Ruby\
**Created:** [August 24, 2007, 10:06pm UTC](https://www.ruby-forum.com/t/fast-check-if-files-exist/112948 "2007-08-24T22:06:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 24, 2007, 10:06pm UTC](https://www.ruby-forum.com/t/fast-check-if-files-exist/112948/1 "2007-08-24T22:06:08Z")

</div>

I have list (array) of file names in the form:

5\_4.3g2  
5\_5.3gp  
5\_6.3gp  
.  
.  
.

What’s the fastest way I can check if these files exist in a given  
directory?

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 24, 2007, 10:12pm UTC](https://www.ruby-forum.com/t/fast-check-if-files-exist/112948/2 "2007-08-24T22:12:13Z")

</div>

On Aug 24, 2007, at 10:05 PM, eggie5 wrote:

> I have list (array) of file names in the form:
> 
> 5\_4.3g2  
> 5\_5.3gp  
> 5\_6.3gp

My bet:

(filenames - Dir.entries(dirname)).empty?

– fxn

---

<div class="post-metadata">

**Author:** ![eggie5](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/7c8e57/32.png) [@eggie5](https://www.ruby-forum.com/u/eggie5)\
**Post date:** [August 24, 2007, 11:32pm UTC](https://www.ruby-forum.com/t/fast-check-if-files-exist/112948/3 "2007-08-24T23:32:38Z")

</div>

On Aug 24, 1:10 pm, Xavier N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> (filenames - Dir.entries(dirname)).empty?
> 
> – fxn

AHHH very clever and it seems to work!

Thanks
