我正在尝试使用正则表达式删除一组目录,但根本没有太多运气,任何人都可以看看目标:
<delete failonerror="true" includeemptydirs="true">
<dirset dir="C:\Users\martin\Desktop\testing" includes="*">
<containsregexp expression="[0-9]*-0" />
</dirset>
</delete>
它只是不会删除文件,我希望它与文件夹[0-9] * - 0匹配,如果匹配,则删除它
答案 0 :(得分:0)
删除任务将删除单个目录,但不删除dirset中的目录。
我有以下目录结构:
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
我创建了这个蚂蚁目标(蚂蚁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>
<!-- Which files are 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>
任务运行后的目录结构:
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
它比生产需要的更冗长,但我希望这有助于未来的regex目录删除!