Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Created June 4, 2015 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save refactorsaurusrex/6404d4975f1613989f76 to your computer and use it in GitHub Desktop.
Save refactorsaurusrex/6404d4975f1613989f76 to your computer and use it in GitHub Desktop.
How to edit the content of a subset of files from within a directory using NAnt. In this example, I iterate recursively through all paths contained within `C:\somePath\dbDirectory\` for all files with the extension of `.sql.template`, load the file, replace all instances of `@DBNAME@` with the value of `${database.name}`, and save the edited fil…
<foreach item="File" property="filename">
<in>
<items>
<include name="C:\somePath\dbDirectory\**.sql.template"/>
</items>
</in>
<do>
<loadfile file="${filename}" property="fileContents">
<filterchain>
<replacetokens>
<token key="DBNAME" value="${database.name}"/>
</replacetokens>
</filterchain>
</loadfile>
<echo file="${string::replace(filename, '.template', '')}"
message="${fileContents}" />
</do>
</foreach>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment