delete file - deleting Ant dirset using regex -
i trying delete set of directories using regex expression, not having luck @ all, can take @ target please:
<delete failonerror="true" includeemptydirs="true"> <dirset dir="c:\users\martin\desktop\testing" includes="*"> <containsregexp expression="[0-9]*-0" /> </dirset> </delete>
it won't delete files, want match folder [0-9]*-0 , if matches it, delete it
the delete task delete individual directory not ones dirset.
i have following directory structure:
c:\dev\debug_investigations\purge_deployment\test\012345-0 c:\dev\debug_investigations\purge_deployment\test\012345-1 c:\dev\debug_investigations\purge_deployment\test\987565-0 c:\dev\debug_investigations\purge_deployment\test\012345-0\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-0\subdir1 c:\dev\debug_investigations\purge_deployment\test\012345-0\subdir2 c:\dev\debug_investigations\purge_deployment\test\012345-0\subdir1\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-0\subdir2\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-1\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir1 c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir2 c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir1\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir2\sometext.txt c:\dev\debug_investigations\purge_deployment\test\987565-0\sometext.txt c:\dev\debug_investigations\purge_deployment\test\987565-0\subdir1 c:\dev\debug_investigations\purge_deployment\test\987565-0\subdir2 c:\dev\debug_investigations\purge_deployment\test\987565-0\subdir1\sometext.txt c:\dev\debug_investigations\purge_deployment\test\987565-0\subdir2\sometext.txt
i created ant target (ant 1.8.2)
<target name="regexptest"> <fileset dir="c:\dev\debug_investigations\purge_deployment\test\" includes="**/**" id="regexp.todelete"> <filename regex="[0-9]*-0" /> </fileset> <!-- files selected? --> <pathconvert pathsep="${line.separator}" property="prop.regexp.test" refid="regexp.todelete" /> <echo message="will delete:" /> <echo message="${prop.regexp.test}" /> <delete failonerror="true" includeemptydirs="true" verbose="true"> <fileset refid="regexp.todelete" /> </delete> </target>
the directory structure after task had run:
c:\dev\debug_investigations\purge_deployment\test\012345-1 c:\dev\debug_investigations\purge_deployment\test\012345-1\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir1 c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir2 c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir1\sometext.txt c:\dev\debug_investigations\purge_deployment\test\012345-1\subdir2\sometext.txt
it's more verbose needs production, hope helps future regex directory deleters!
Comments
Post a Comment