File.open () Errno::ENOTDIR

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

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")

···

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