File.open () Errno::ENOTDIR

  • Thread starter Rebhan, Gilbert
  • Start date
R

Rebhan, Gilbert

Hi,

i have a problem with File.open =3D

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


gives me =3D

Not a directory - ... (Errno::ENOTDIR)
=09

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



Gilbert
 
B

Brian Candler

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,234
Messages
2,571,178
Members
47,811
Latest member
Adisty

Latest Threads

Top