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

About this user

James Robertson http://www.r0bertson.co.uk

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Create a file directory listing in XML

// 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
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS