I am trying to write to a file inside a subdirectory. This file is created by the code but, once the file is created, it is empty after the script finishes its execution. What am I doing wrong?
# Creating output files print "Creating output files and filling root menu..." FileUtils.cd(outdir) do file = File.new("directory.xml", "w") file.puts "<?php header(\"Content-type: text/xml\"); ?>" file.puts "<CiscoIPPhoneMenu>" file.puts "<Title>Telefonbuch</Title>" file.puts "<Prompt>Dir External</Prompt>" letters_used.each do |letter| filename = "contacts_" + letter + ".xml" FileUtils.touch(filename) file.puts "<MenuItem>" file.puts "<Name>" + letter.upcase + "</Name>" file.puts "<URL>http://" + HOSTNAME + WEBSERV_DIR + "/" + filename + "</URL>" file.puts "</MenuItem>" end file.puts "</CiscoIPPhoneMenu>" file.rewind end print "Done\n" "directory.xml" should link to each "contacts_letter.xml" file, which is created by the script too, however directory.xml is empty. Why?
file.rewindwithfile.closecloseflushes automatically - ruby-doc.org/core-1.9.3/IO.html#method-i-close