【问题标题】:Concatenating Files - Including files in folders连接文件 - 包括文件夹中的文件
【发布时间】:2012-08-01 13:21:34
【问题描述】:

我目前有这个命令:

copy /b *.txt newfile.txt

但我也想包含所有带有文件夹的文件。

我该怎么做?是否也可以将其添加到 Apache Ant 中? 我也考虑这样做来缩小 JS 文件。

我正在使用 windows 并且想要一个命令来运行或批处理文件但有问题。

还有什么要删除的行吗? 有没有比我目前使用的命令更好的命令?

更新:

<target name="concatenate" description="Concatenate all js files">
    <concat destfile="build/application.js">
        <fileset dir="js" includes="*.js" />
    </concat>
</target>
<target name="compress" depends="concatenate" description="Compress application.js to application-min.js">
    <apply executable="java" parallel="false">
        <filelist dir="build" files="application.js" />
        <arg line="-jar" />
        <arg path="C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" />
        <srcfile />
        <arg line="-o" />
        <mapper type="glob" from="*.js" to="build/*-min.js" />
        <targetfile />
    </apply>

现在我正在使用上面的代码,但不能让它在文件夹中包含文件

【问题讨论】:

标签: file ant command-line batch-file concatenation


【解决方案1】:

正如oers 在评论中指出的那样,Ant 模式使用** 递归匹配目录。这是 Ant 手册中相关的 Patterns 部分:

为了让事情更加灵活,我们添加了一项额外的功能,它可以匹配多个目录级别。这可用于匹配完整的目录树,或目录树中任何位置的文件。为此,** 必须用作目录的名称。当** 用作模式中目录的名称时,它匹配零个或多个目录。例如:/test/** 匹配/test/, 下的所有文件/目录,例如/test/x.java,/test/foo/bar/xyz.html,,但不匹配/xyz.xml

有一个“速记”:如果模式以/\ 结尾,则附加**。例如,mypackage/test/ 被解释为好像是mypackage/test/**

上面的“连接”目标是:

<target name="concatenate" description="Concatenate all js files">
  <concat destfile="build/application.js">
    <fileset dir="js" includes="**/*.js" excludes="**/*.min.js" />
  </concat>
</target>

【讨论】:

  • 非常好的答案,如果我想排除 .min.js 等文件但允许 .js 我该怎么做?
  • 有没有办法做到这一点,但按一定的顺序?
  • @LiamMcCann,查看更新的答案,显示如何排除以 *.min.js 结尾的文件。
猜你喜欢
  • 2019-08-15
  • 1970-01-01
  • 1970-01-01
  • 2015-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-30
  • 1970-01-01
相关资源
最近更新 更多