[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

File.open () Errno::ENOTDIR

Rebhan, Gilbert

2/9/2007 2:13:00 PM


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


1 Answer

Brian Candler

2/9/2007 2:46:00 PM

0

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