Forum: Ruby File.open () Errno::ENOTDIR

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C6ec9468bab19475922dd29d00714da8?d=identicon&s=25 Rebhan, Gilbert (Guest)
on 2007-02-09 15:14
(Received via mailing list)
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
753dcb78b3a3651127665da4bed3c782?d=identicon&s=25 Brian Candler (Guest)
on 2007-02-09 15:47
(Received via mailing list)
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")
This topic is locked and can not be replied to.