From: Heesob Park Date: 2009-03-08T21:52:49+09:00 Subject: Re: I code my first ruby script, and it got problem! 2009/3/8 Power One : > Heesob Park wrote: >> Hi, >> >> 2009/3/8 Power One : >>> creating directory "land", the script creates a directory "land?".  How >>> can I solve this problem?  You can see my script at >>> http://pastie.org/410753. >> You actually created directory not "land?" but "land\n" >> >> The line # 5 of your code >>   if @dirname = gets >> should be >>   if @dirname = gets.chomp >> >> >> Regards, >> >> Park Heesob > > Thanks Park Heesob, > > gets.chomp did the job perfectly, but my very last code is like > @letst.del_dir which is calling the "def del_dir" is not working. > > I think Dir.delete is the wrong way to use for deleting a directory? > > def del_dir >    if File.exist?("#{@dirname}") >      puts "I'm going to delete your directory #{@dirname}" >      Dir.delete("#{@dirname}") >      puts "#{@dirname} has been deleted." >    else >      puts "#{@dirname} is still here!" >    end >    end > The del_dir method has no problem. The problem is due to see_me method. Modify see_me something like this will work. def see_me if File.exist?("#{@dirname}") cwd = Dir.pwd begin Dir.chdir("#{@dirname}") puts Dir.pwd ensure Dir.chdir(cwd) end else puts "This directory #{@dirname} is not exist!" end end Regards, Park Heesob