# File.open () Errno::ENOTDIR

**URL:** <https://www.ruby-forum.com/t/file-open-errno-enotdir/85048>\
**Category:** Ruby\
**Created:** [February 9, 2007, 3:14pm UTC](https://www.ruby-forum.com/t/file-open-errno-enotdir/85048 "2007-02-09T15:14:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 9, 2007, 3:14pm UTC](https://www.ruby-forum.com/t/file-open-errno-enotdir/85048/1 "2007-02-09T15:14:41Z")

</div>

Hi,

i have a problem with File.open =

File.open(SRCDIR\<\<’/’\<\<Dir.entries(SRCDIR).sort[2]\<\<’/foobar.TXT’) do  
|f|  
mymethod(x)  
end

gives me =

Not a directory - … (Errno::ENOTDIR)

How to get the Dirname Dir.entries(SRCDIR).sort[2] into the string  
for method File.open ?

Gilbert

---

<div class="post-metadata">

**Author:** ![RebhanS\_Gilbert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7feea3/32.png) [@RebhanS\_Gilbert](https://www.ruby-forum.com/u/RebhanS_Gilbert)\
**Post date:** [February 9, 2007, 3:47pm UTC](https://www.ruby-forum.com/t/file-open-errno-enotdir/85048/2 "2007-02-09T15:47:43Z")

</div>

On Fri, Feb 09, 2007 at 11:12:46PM +0900, Rebhan, Gilbert wrote:

> i have a problem with File.open =
> 
> File.open(SRCDIR\<\<’/’\<\<Dir.entries(SRCDIR).sort[2]\<\<’/foobar.TXT’) do  
> |f|  
> mymethod(x)  
> end

Warning:

```
string1 << string2

```

modifies string1 by adding the contents of string2. So here you are  
modifying SRCDIR, which is probably not what you want, especially if  
you’re  
going round this in a loop.

SRCDIR=’/tmp’  
puts SRCDIR\<\<’/bar’ # ‘/tmp/bar’  
puts SRCDIR # ‘/tmp/bar’

Use + to concatenate two strings and get the result as a third,  
newly-created string.

> How to get the Dirname Dir.entries(SRCDIR).sort[2] into the string  
> for method File.open ?

File.open(SRCDIR + ‘/’ + Dir.entries(SRCDIR).sort[2] + ‘/foobar.TXT’)

or

File.open("#{SRCDIR}/#{Dir.entries(SRCDIR).sort[2]}/foobar.TXT")
