-1

Bard gave me this program for Windows but it doesn't work. Says it can't find the file Any suggestions.

   def generate_file(filename)
   file = File.open(filename, 'w')
   file.puts 'This is the content of the file.'
   file.close

   # Open the file in RubyMine
   system("start #{filename}")
   end

   filename = 'my_file.txt'
   generate_file(filename)`
lazy_coder
  • 13
  • 4
  • 1
    1. Why would you trust AI to generate correct code? 2. Do you understand each and every line of that code? 3. What do you expect to happen when you run this? 4. What happened? Show the actual error messages, "it doesn't work" and "Says it can't find the file" are too vague. 5. What do you mean when you say you want to "have the creation program open it"? Do you mean you expect it to open in RubyMine? Why would you expect RubyMine to be the default Windows association for a `.txt` file? – pjs Aug 19 '23 at 21:46
  • 1
    6. Where do you expect `my_file.txt` to be written? Have you done a search to see if the file exists somewhere (possibly other than where you looked for it)? 7. Properly indent your code. 8. Typos in the subject line and missing punctuation tend to reflect poorly on whether somebody reviewed and edited their question before submitting it. – pjs Aug 19 '23 at 21:47

0 Answers0