Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Create a file directory listing in XML (See related posts)

// This code lists the filenames in the current directory which have a .xml extension, then saves them to an XML file.called 'dir.xml'.

require 'rexml/document'

include REXML

class Xmldirectory
  def initialize
  end

  def create_directory_file
    file = File.new('dir.xml','w')
    doc = Document.new
    doc.add_element('dir')

    Dir["*.xml"].each do |x|
      entry = Element.new('file')
      entry.text = x
      doc.root.add_element entry
    end
    file.puts doc
    file.close
  end
end

You need to create an account or log in to post comments to this site.


Click here to browse all 5147 code snippets

Related Posts