# Newbie question

**URL:** <https://rubytalk.org/t/newbie-question/323>\
**Category:** ruby-talk\
**Created:** [19 June 2002 20:26 UTC](https://rubytalk.org/t/newbie-question/323 "2002-06-19T20:26:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Merrick](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@Steve\_Merrick](https://rubytalk.org/u/Steve_Merrick)\
**Post date:** [19 June 2002 20:26 UTC](https://rubytalk.org/t/newbie-question/323/1 "2002-06-19T20:26:31Z")

</div>

My first Ruby program is an equivalent of the MS-DOS ‘dir’ command -  
just for learning purposes, you understand! 😉

I can’t seem to find the method that will tell me whether or not a file  
exists. File.stat(“filename”).file? (and similar methods) throw a system  
error if the file doesn’t exist.

Help a newbie out? TIA. 🙂

> **···**
>
> –  
> Steve Merrick
> 
> “Who cares, wins”

---

<div class="post-metadata">

**Author:** ![Lyle\_Johnson1](https://avatars.discourse-cdn.com/v4/letter/l/bcef8e/32.png) [@Lyle\_Johnson1](https://rubytalk.org/u/Lyle_Johnson1)\
**Post date:** [19 June 2002 20:26 UTC](https://rubytalk.org/t/newbie-question/323/2 "2002-06-19T20:26:33Z")

</div>

> I can’t seem to find the method that will tell me whether or not a file  
> exists. File.stat(“filename”).file? (and similar methods) throw a system  
> error if the file doesn’t exist.

You were close:

```
File.exists?("filename") -> true or false

```

HTH,

Lyle

---

<div class="post-metadata">

**Author:** ![Pablo\_Lorenzzoni](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@Pablo\_Lorenzzoni](https://rubytalk.org/u/Pablo_Lorenzzoni)\
**Post date:** [19 June 2002 20:46 UTC](https://rubytalk.org/t/newbie-question/323/3 "2002-06-19T20:46:02Z")

</div>

Hello,

I am also a newbie, but I think you’re in the wrong path. According to the  
Pragmatic Programmers Guide you should be using FileTest module. They sugest:  
FileTest.exist?(‘filename’)

I believe File class import FileTest automatically. If this is true,  
File.exist?(‘filename’) should work as well. (I haven’t tested it, though)

s

Pablo

> **···**
>
> Em Qua 19 Jun 2002 17:26, Steve Merrick escreveu:
> 
> > My first Ruby program is an equivalent of the MS-DOS ‘dir’ command -  
> > just for learning purposes, you understand! 😉
> > 
> > I can’t seem to find the method that will tell me whether or not a file  
> > exists. File.stat(“filename”).file? (and similar methods) throw a system  
> > error if the file doesn’t exist.
> > 
> > Help a newbie out? TIA. 🙂
> 
> –  
> Pablo Lorenzzoni (Spectra) [spectra@debian.org](mailto:spectra@debian.org)  
> GnuPG Key ID 268A084D at [search.keyserver.net](http://search.keyserver.net)  
> Webpage: [http://people.debian.org/~spectra/](http://people.debian.org/~spectra/)

---

<div class="post-metadata">

**Author:** ![Han\_Holl4](https://avatars.discourse-cdn.com/v4/letter/h/d2c977/32.png) [@Han\_Holl4](https://rubytalk.org/u/Han_Holl4)\
**Post date:** [19 June 2002 21:23 UTC](https://rubytalk.org/t/newbie-question/323/4 "2002-06-19T21:23:12Z")

</div>

Steve Merrick wrote:

Have a look at Kernel#test for the entire Perl/shell scala of tests.

> **···**
>
> > My first Ruby program is an equivalent of the MS-DOS ‘dir’ command -  
> > just for learning purposes, you understand! 😉
> > 
> > I can’t seem to find the method that will tell me whether or not a file  
> > exists. File.stat(“filename”).file? (and similar methods) throw a system  
> > error if the file doesn’t exist.
> > 
> > Help a newbie out? TIA. 🙂
> > 
> > –  
> > Steve Merrick
> > 
> > “Who cares, wins”

---

<div class="post-metadata">

**Author:** ![Steve\_Merrick](https://avatars.discourse-cdn.com/v4/letter/s/ac8455/32.png) [@Steve\_Merrick](https://rubytalk.org/u/Steve_Merrick)\
**Post date:** [20 June 2002 09:28 UTC](https://rubytalk.org/t/newbie-question/323/5 "2002-06-20T09:28:00Z")

</div>

Thanks all! As a C++ programmer, I’m not used to looking for mixins, so  
I failed to notice FileTest. ☹ The ‘dir’ project continues, and I’m  
learning lots. 🙂

> **···**
>
> –  
> Steve Merrick
> 
> “Who cares, wins”  
> “Han Holl” [han@pobox.com](mailto:han@pobox.com) wrote in message  
> [news:3D10F63B.8030502@pobox.com](mailto:news:3D10F63B.8030502@pobox.com)…
> 
> > Steve Merrick wrote:
> > 
> > Have a look at Kernel#test for the entire Perl/shell scala of tests.
> > 
> > > My first Ruby program is an equivalent of the MS-DOS ‘dir’ command -  
> > > just for learning purposes, you understand! 😉
> > > 
> > > I can’t seem to find the method that will tell me whether or not a  
> > > file  
> > > exists. File.stat(“filename”).file? (and similar methods) throw a  
> > > system  
> > > error if the file doesn’t exist.
> > > 
> > > Help a newbie out? TIA. 🙂
> > > 
> > > –  
> > > Steve Merrick
> > > 
> > > “Who cares, wins”
