Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using a variable in File.new or File.open

Status
Not open for further replies.

imarosel

Technical User
Jun 23, 2005
149
US
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?


 
need to put g=File.open(newFileName.chomp!,"w")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top