Skip to content

Instantly share code, notes, and snippets.

@millermedeiros
Created February 14, 2011 20:27
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 millermedeiros/826481 to your computer and use it in GitHub Desktop.
Save millermedeiros/826481 to your computer and use it in GitHub Desktop.
Example Ant task to copy/delete folders
<?xml version="1.0" encoding="utf-8"?>
<project name="example-purge-copy" default="" basedir=".">
<!-- properties -->
<!-- make sure you are pointing to the right folder since purgeDeploy can delete undesired files... -->
<property name="deploy.dir" value="../../deploy" />
<!-- custom tasks -->
<!-- targets -->
<target name="-mkdirs" description="Make required dirs.">
<echo message="Creating required directories..."/>
<mkdir dir="${deploy.dir}"/>
</target>
<target name="purgeDeploy" description="Delete old deploy files.">
<echo message="Deleting old deploy files..."/>
<delete includeEmptyDirs="true">
<fileset dir="${deploy.dir}">
<include name="**" />
<exclude name="**/.svn" /> <!-- skip .svn folders otherwise it will cause SVN conflicts -->
</fileset>
</delete>
<antcall target="-mkdirs"/>
</target>
<target name="copyToDeploy" description="Copy files to deploy folder.">
<copy todir="${deploy.dir}">
<fileset dir="${basedir}">
<include name="**" />
<exclude name="**/_*/**" /> <!-- ignore files/folders starting with underscore -->
<exclude name="**/.svn" />
<exclude name="**/.git" />
<exclude name="**/.hg" />
<exclude name="**/.DS_Store" />
<exclude name="**/.tmp*" />
<exclude name="**/.project" />
<exclude name="**/.livereload" />
<exclude name="**/.jshintrc" />
<exclude name="**/.settings/**" />
<exclude name="build.xml" />
</fileset>
</copy>
</target>
</project>
@millermedeiros
Copy link
Author

If you want to delete all the old files before copying to deploy folder add depends="purgeDeploy" to the copyToDeploy target.. I've removed it from the example to avoid undesired side effects.

PS: Ant is usually smart enough to copy only files that changed but in most of my build tasks I usually call purgeDeploy before copyToDeploy since I'm usually generating files that have a unique name and/or that should be discarded or replaced at each build.

@millermedeiros
Copy link
Author

I've created a similar script using node.js. See Gist 2640642

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment