# Checking for file existance

**URL:** <https://rubytalk.org/t/checking-for-file-existance/1185>\
**Category:** ruby-talk\
**Created:** [14 August 2002 00:25 UTC](https://rubytalk.org/t/checking-for-file-existance/1185 "2002-08-14T00:25:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio](https://avatars.discourse-cdn.com/v4/letter/m/90db22/32.png) [@Mauricio](https://rubytalk.org/u/Mauricio)\
**Post date:** [14 August 2002 00:25 UTC](https://rubytalk.org/t/checking-for-file-existance/1185/1 "2002-08-14T00:25:25Z")

</div>

Hi,

```
How do I check if a file (possibly a directory) exists? This is probably

```

easy, but I was not able to find it.

```
Thanks,
Maurício
```

---

<div class="post-metadata">

**Author:** ![Rich1](https://avatars.discourse-cdn.com/v4/letter/r/e56c9b/32.png) [@Rich1](https://rubytalk.org/u/Rich1)\
**Post date:** [14 August 2002 00:59 UTC](https://rubytalk.org/t/checking-for-file-existance/1185/2 "2002-08-14T00:59:22Z")

</div>

It’s kinda hard to find - the FileTest object is what you’re looking for

The method ‘exists?’ can tell you if it exists…

The method ‘file?’ can tell you if it’s a file…

The method ‘directory?’ can tell you if it’s a directory…

But I use

returnedString = File.ftype (“nameOfFile\_or\_directory”)

```
Which returns strings like - ``file'', ``directory'',

```

`characterSpecial'', `blockSpecial’‘, `fifo'', `link’‘, or ``socket’'.  
(taken from the Ruby help files…)

-Rich

> **···**
>
> ----- Original Message -----  
> From: “Maurício” [briqueabraque@yahoo.com](mailto:briqueabraque@yahoo.com)  
> Newsgroups: gmane.comp.lang.ruby.general  
> To: “ruby-talk ML” [ruby-talk@ruby-lang.org](mailto:ruby-talk@ruby-lang.org)  
> Sent: Tuesday, August 13, 2002 6:25 PM  
> Subject: Checking for file existance
> 
> > Hi,
> > 
> > ```
> > How do I check if a file (possibly a directory) exists? This is
> > 
> > ```
> 
> probably
> 
> > easy, but I was not able to find it.
> > 
> > ```
> > Thanks,
> > Maurício
> > 
> > ```

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [14 August 2002 01:55 UTC](https://rubytalk.org/t/checking-for-file-existance/1185/3 "2002-08-14T01:55:57Z")

</div>

Hi,

> **···**
>
> At Wed, 14 Aug 2002 09:25:25 +0900, Maurício wrote:
> 
> > ```
> > How do I check if a file (possibly a directory) exists? This is probably
> > 
> > ```
> > 
> > easy, but I was not able to find it.
> 
> File.exist?(“filename”)
> 
> –  
> Nobu Nakada
