-2

I have this code:

 File.open(“MIO.TA.1234567.#{Time.now.strftime(“%F”)}.{Time.now.strftime  
 (“%T”)}.xml”, “w”) { |file| file.write(xml) }

The only requirement is to be able to save to MIO.TA.1234567.20180309.090000.xml instead of having to have output.xml existing and me having to open to write.

GLH
  • 177
  • 1
  • 2
  • 10

1 Answers1

0

What you're already doing is correct.

The file you name doesn't need to already exist, and the first argument of File.open will take the path to a file, so you can write anywhere you like.

See this question for reference.

jon1467
  • 89
  • 2
  • 7
  • I have just realized this, I have tried to now change the file naming convention like so: File.open(“MIO.TA.1234567.#{Time.now.strftime(“%F”)}. {Time.now.strftime(“%T”)}.xml”, “w”) { |file| file.write(xml) } This produces an error: syntax error unexpected , – GLH Mar 09 '18 at 12:17
  • It's possibly because of the missing # character for your second `Time` call, which means your quotes are messing up the overall string. – jon1467 Mar 09 '18 at 12:23