如何删除不在另一个目录present文件? [英] How to delete files that are not present in another directory?

查看:240
本文介绍了如何删除不在另一个目录present文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个目录,我们姑且称之为的src 建立。我的构建系统的工作原理,这样的比的mtime最近在的src 所有文件建立它直接复制文件的src 打造专业化并做一些变换(缩小,版本等)。因为文件被认为是最新的,否则跳过。

然而,这造成在源文件被删除,因为其内置版本仍然是present在建立键,进入后生成的地图文件有问题。

  $ LS SRC
example1.js
example2.js$蚂蚁做最东西
...$ LS建设
example1.js
example1-12345.min.js
example2.js
example2-23456.min.js
。地图$猫.MAP
example1.js = example1-12345.min.js
example2.js = example2-23456.min.js$ RM的src / example2.js
$蚂蚁做最东西
...$猫.MAP
example1.js = example1-12345.min.js
example2.js = example2-23456.min.js

有没有办法删除文件没有present与蚂蚁另一个目录?但从集理论一点上,它是一个简单的A \\ B的操作。

这是我已经尝试过,但没有工作:

 <删除DIR =打造>
    <排除NAME =SRC / */>
< /删除><删除DIR =打造>
    <&排除GT;
        <文件集的名称=SRC/>
    < /排除>
< /删除><删除DIR =打造>
    <文件集DIR =构建/ *>
        <而非>
            < present TARGETDIR =SRC/>
        < /&不GT;
    < /文件集>
< /删除>


解决方案

有没有办法删除文件不是在另一个目录present与蚁族结果
是的,使用删除任务用的文件集http://ant.apache.org/manual/Types/selectors.html#$相对=nofollow p $ psentselect相对=nofollow> presentselector ,FE结果

 <文件集DIR =/家/玫瑰花蕾/温度/ DIR1包括= ID =srcfileset&GT*罐子。
 < present present =srconlyTARGETDIR =/家/玫瑰花蕾/温度/ DIR2/>
< /文件集>
<回声>文件只在/ home /玫瑰花蕾/温度/ DIR1 => $ {的toString:srcfileset}< /回声>
<删除>
 <文件集REFID =srcfileset/>
< /删除>

将删除所有文件仅present在/ home /玫瑰花蕾/温度/ DIR1结果
对于各地使用另一种方式:结果

  ...
 <而非>
  < present present =srconlyTARGETDIR =/家/玫瑰花蕾/温度/ DIR2/>
 < /&不GT;
...

又见 http://stackoverflow.com/a/12847012/130683 使用$ P $另一个例子psent选择

I have two directories, let's call them src and build. My build system works so that for all files with mtime more recent in src than in build it copies the file from src to buid and does some transformations (minification, versioning, etc.). Otherwise skips as the file is considered up to date.

This however poses a problem when source file is deleted, as its built version is still present in build and gets into map file generated afterwards.

$ ls src
example1.js
example2.js

$ ant do-the-stuff
...

$ ls build
example1.js
example1-12345.min.js
example2.js
example2-23456.min.js
.map

$ cat .map
example1.js=example1-12345.min.js
example2.js=example2-23456.min.js

$ rm src/example2.js
$ ant do-the-stuff
...

$ cat .map
example1.js=example1-12345.min.js
example2.js=example2-23456.min.js

Is there a way to delete files not present in another directory with Ant? From set theory point of view it's a simple A\B operation.

This is what I have tried already but didn't work:

<delete dir="build">
    <exclude name="src/*" />
</delete>

<delete dir="build">
    <exclude>
        <fileset name="src" />
    </exclude>
</delete>

<delete dir="build">
    <fileset dir="build/*">
        <not>
            <present targetdir="src" />
        </not>
    </fileset>
</delete>

解决方案

"Is there a way to delete files not present in another directory with Ant"
yes, use delete task with a fileset using a presentselector, f.e.

<fileset dir="/home/rosebud/temp/dir1" includes="*.jar" id="srcfileset">
 <present present="srconly" targetdir="/home/rosebud/temp/dir2"/>
</fileset>
<echo>Files only in /home/rosebud/temp/dir1 => ${toString:srcfileset}</echo>
<delete>
 <fileset refid="srcfileset"/>
</delete>

would delete all files only present in /home/rosebud/temp/dir1
for the other way around use :

...
 <not>
  <present present="srconly" targetdir="/home/rosebud/temp/dir2"/>
 </not>
...

see also http://stackoverflow.com/a/12847012/130683 for another example using the present selector

这篇关于如何删除不在另一个目录present文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆