# Fast check if files exist

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

<div class="post-metadata">

**Author:** ![Gavin\_Kistner](https://avatars.discourse-cdn.com/v4/letter/g/ed655f/32.png) [@Gavin\_Kistner](https://rubytalk.org/u/Gavin_Kistner)\
**Post date:** [24 August 2007 20:08 UTC](https://rubytalk.org/t/fast-check-if-files-exist/40173/1 "2007-08-24T20:08:28Z")

</div>

> I have list (array) of file names in the form:
> 
> What's the fastest way I can check if these files exist in a given  
> directory?

Dir.chdir( source\_directory ) do  
&nbsp;&nbsp;my\_array.each do |file\_name|  
&nbsp;&nbsp;&nbsp;&nbsp;if File.exist?( file\_name )  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;&nbsp;else  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
end

> **···**
>
> From: eggie5 [mailto:eggie5@gmail.com]

---

<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/40173/2 "2007-08-24T21:30:04Z")

</div>

Thanks, I like this a lot.

> **···**
>
> On Aug 24, 1:08 pm, "Gavin Kistner" \<gavin.kist...@anark.com\> wrote:
> 
> > From: eggie5 [mailto:egg...@gmail.com]
> > 
> > \> I have list (array) of file names in the form:
> > 
> > \> What's the fastest way I can check if these files exist in a given  
> > \> directory?
> > 
> > Dir.chdir( source\_directory ) do  
> > &nbsp;&nbsp;my\_array.each do |file\_name|  
> > &nbsp;&nbsp;&nbsp;&nbsp;if File.exist?( file\_name )  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
> > &nbsp;&nbsp;&nbsp;&nbsp;else  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;end  
> > end
