# Fast check if files exist

**URL:** <https://rubytalk.org/t/fast-check-if-files-exist/40172>\
**Category:** ruby-talk\
**Created:** [24 August 2007 20:05 UTC](https://rubytalk.org/t/fast-check-if-files-exist/40172 "2007-08-24T20:05:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eggie5](https://avatars.discourse-cdn.com/v4/letter/e/7c8e57/32.png) [@eggie5](https://rubytalk.org/u/eggie5)\
**Post date:** [24 August 2007 20:05 UTC](https://rubytalk.org/t/fast-check-if-files-exist/40172/1 "2007-08-24T20:05:05Z")

</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:** ![Xavier\_Noria](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/xavier_noria/32/1867_2.png) [@Xavier\_Noria](https://rubytalk.org/u/Xavier_Noria)\
**Post date:** [24 August 2007 20:10 UTC](https://rubytalk.org/t/fast-check-if-files-exist/40172/2 "2007-08-24T20:10:18Z")

</div>

My bet:

&nbsp;&nbsp;&nbsp;(filenames - Dir.entries(dirname)).empty?

-- fxn

> **···**
>
> 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

---

<div class="post-metadata">

**Author:** ![eggie5](https://avatars.discourse-cdn.com/v4/letter/e/7c8e57/32.png) [@eggie5](https://rubytalk.org/u/eggie5)\
**Post date:** [24 August 2007 21:30 UTC](https://rubytalk.org/t/fast-check-if-files-exist/40172/3 "2007-08-24T21:30:04Z")

</div>

AHHH very clever and it seems to work!

Thanks

> **···**
>
> On Aug 24, 1:10 pm, Xavier Noria \<f...@hashref.com\> wrote:
> 
> > 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:
> > 
> > &nbsp;&nbsp;&nbsp;(filenames - Dir.entries(dirname)).empty?
> > 
> > -- fxn
