No commit activity in last 3 years
No release in over 3 years
A command line executable for renaming XML files to content of an XML tag.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

= 1.6.1
 Project Readme

#xml_file_renamer

This is a Ruby class that allows you to rename your XML files based on content inside the file.

##Use Case Scenario:

####You have multiple files named like:

building_589989.xml, building_589990.xml, building_589991.xml

####You want the files to be named:

Columbia Tower.xml, Space Needle.xml, Premiere on Pine.xml

####Where "Columbia Tower" is a text node, that you can locate by traversing tag names:

'building Contact building_name'

##Solution:

###Install:

Install the gem from rubygems.org

$ gem install xml_file_renamer

###Run the command:

  $ xml_file_renamer '<source_data>' '<tag_names>' [<case>]

###Examples:

Copy example XML files provided by the gem:

$ cp -r `which xml_file_renamer`/../../gems/xml_file_renamer-0.0.9/example_xml_files ~/Documents/example_xml_files

Run the command on a single file:

$ xml_file_renamer \
~/Documents/example_xml_files/example_building_589989.xml \
'building Contact building_name'

Output:

**** Origin Directory: /Users/sealocal/Documents/example_xml_files
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
**** Tag Names: building Contact building_name
**** Source File: example_building_589989.xml
**** New File Name: Columbia Center

Instead of a single file, run the command on a directory (non-recursive):

$ xml_file_renamer ~/Documents/example_xml_files 'building Contact building_name'

Output:

**** Origin Directory: /Users/sealocal/Documents/example_xml_files
**** Export Directory: /Users/sealocal/Documents/example_xml_files/export_folder
**** Tag Names: building Contact building_name
**** Source File: example_building_589989.xml
**** New File Name: Columbia Center
**** Source File: example_building_589990.xml
**** New File Name: Space Needle
**** Source File: example_building_589991.xml
**** New File Name: Premiere on Pine

Case Option:

Case options will convert the case of the new string:

$ xml_file_renamer building.xml 'building Contact building_name' lower_case

These are valid options:

lower_case  #=> 'space needle.xml'
upper_case  #=> 'SPACE NEEDLE.xml'
title_case  #=> 'Space Needle.xml'
camel_case  #=> 'SpaceNeedle.xml'
snake_case  #=> 'space_needle.xml'

####Notes:

  1. <source_data> must contain an XML tree, with a match for your tag names.

  2. <source_data> can have ANY file extension. As long as it HAS a file extension, this utility will find your file an rename it.

  3. <source_data> can be a relative or absolute path to an XML file.

  4. The output will be saved to an export_folder, until this project is otherwise updated.

  5. The utility does not recursively find files in sub-directories. When given a directory, only files in that directory will be processed.

##Contribute: Please STAR, FORK, or create a new ISSUE if you would like to see this project developed further. We can even rename the project when appropriate!