arose
6/8/2006 10:35:00 PM
Ok might have something to do with file.new if i do the following:
g=File.open("Reader.txt","r")
g.each_line {|line| File.new((line).chomp)}
I get the "no file name or directory" error. if i have line.dump there
seems to be double quotes around what is read from Reader.txt?!?!?!?
This works:
g=File.open("Reader.txt","r")
g.each_line {|line| File.open((line).chomp, "w")}
I have been assuming File.new makes a new file and File.open,
opens one that exists. That is strange.
Any advice?
arose wrote:
> man i have a long ways to go, neither of those seem to work
>
> the first option gives me the error Invalid argument '
> "ThisIsMyFileName" (the first row of Reader.txt)
>
> the second one gives" me the error no such file or directory -
> ThisIsMyFileName"
>
>
> Tim Hoolihan wrote:
> > Like this:
> > g=File.open("Reader.txt","r")
> > g.each_line {|line| File.new((line.dump).chomp)}
> >
> > But it's probably more graceful if you just do it like this:
> > File.open("Reader.txt") {|g|
> > while line = g.gets
> > File.new(line)
> > end
> > }
> >
> > arose wrote:
> > > How would you work chomp! into the following
> > >
> > > g=File.open("Reader.txt","r")
> > > g.each_line {|line| File.new(line.dump)}
> > >
> > >
> > > arose wrote:
> > >> that was it, thanks a lot
> > >>
> > >> Bit Twiddler wrote:
> > >>> "arose" <arosel@ercot.com> wrote in message
> > >>> news:1149715756.407284.310620@i39g2000cwa.googlegroups.com...
> > >>>> I am trying to make a list of filenames in a txt file and have those
> > >>>> files generated.
> > >>>>
> > >>>> g=File.open("Reader.txt","r")
> > >>>> g.each_line {|line| File.new(line.dump)}
> > >>>>
> > >>>> I get an error message "Invalid argument - "ThisIsMyFileName.txt" which
> > >>>> is the first name in the Reader.txt file
> > >>>> and it points to the second line of my code above.
> > >>>>
> > >>>> I try something similar like this
> > >>>>
> > >>>> puts "What do you want to call your text file?"
> > >>>> newFileName=gets
> > >>>> g=File.open(newFileName,"w")
> > >>>> g.close()
> > >>>>
> > >>>> I get an error "invalid Argument - whatever i type in"
> > >>>>
> > >>>> If i try this though it works.
> > >>>> newFileName="Imadeafile"
> > >>>> g=File.open(newFileName,"w")
> > >>>> g.close()
> > >>>>
> > >>>> I'm super new to Ruby, in fact this is my first program. What concept
> > >>>> am I missing here?
> > >>> Don't you have to do a String#chomp on the filename that you read in (from
> > >>> the file or stdin)? This will remove the trailing newline character.
> > >>>
> > >>> For example: g=File.open(newFileName.chomp!,"w")
> > >