# Re: Fast check if files exist

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

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [August 24, 2007, 10:09pm UTC](https://www.ruby-forum.com/t/re-fast-check-if-files-exist/112951/1 "2007-08-24T22:09:09Z")

</div>

From: eggie5 [[mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)]

> 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  
my\_array.each do |file\_name|  
if File.exist?( file\_name )  
…  
else  
…  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [August 24, 2007, 11:30pm UTC](https://www.ruby-forum.com/t/re-fast-check-if-files-exist/112951/2 "2007-08-24T23:30:38Z")

</div>

On Aug 24, 1:08 pm, “Gavin K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> ...
> else
> ...
> end
> 
> ```
> 
> end  
> end

Thanks, I like this a lot.
