Here is my directory structure:
module/
a/
foo.php
b/
bar.php
b/
c/
I would like to run a command for each directory under module/ but non recursively, so only these should be included:
a/
b/
c/
If I do this:
<target name="foo">
<apply executable="ls">
<arg value="-l" />
<fileset dir="${basedir}/module/">
</fileset>
</apply>
</target>
This will run recursively for each directory and file under module.
You only want to do this in the first level of directories?
<target name="foo">
<apply executable="ls">
<arg value="-l" />
<dirset dir="${basedir}/module/">
<include name="*"/>
</dirset>
</apply>
</target>
Note the <include>. I'm specifying only the directories immediately under the directory I specified in my <dirset/>. If I said, <include names="**/*"/>, it would specify all directories.
When you are dealing with directories and not files, use <dirset/> and not <fileset/>. <fileset/> is for specifying files. <dirset/> is for specifying directories.
Related
Ant has inbuilt Copy task to copy multiple files.
I tried to define following target in build.xml file
<target name="copyFile">
<copy todir="../CHECK">
<fileset dir=".">
<patternset id="AllFiles">
<include name="*"/>
</patternset>
</fileset>
</copy>
</target>
It is copying files and directories. However content within directories is not copied, instead directories are copied as empty to destination "../CHECK". Does Ant copy task provides capability to do recursive copy of files and directories
I found the answer
name pattern in include should be "**" instead of "*". It does recursive copy of all contents
<target name="copyFile">
<copy todir="../CHECK">
<fileset dir=".">
<patternset id="AllFiles">
<include name="**"/>
</patternset>
</fileset>
</copy>
</target>
I have an ant file to generate coffeescript documentation with docco. It works fine, except that it currently dumps all of the documentation file into the docs folder. I'd like the docs folder to mirror the structure of my scripts directory, rather than just having all files dumped flat into one directory.
<target name="documentation" description="Generate Docco Documentation for coffee files">
<apply executable="docco" verbose="true" force="true" failonerror="true">
<srcfile />
<fileset dir ="${src.script.dir}" >
<include name="**/*.coffee"/>
</fileset>
</apply>
</target>
I know docco has an --output argument, but my I'm not sure how to generate the docs directory path in the docs folder for each file in the fileset without going through them 1 by 1.
Using <srcfile> and <targetfile> parameters for apply task should solve the problem.
Here's an example that moves files with .a extension to .b extension:
<apply executable="mv" dir="./" relative="true">
<mappedresources>
<fileset dir="." includes="**/*.a"/>
</mappedresources>
<mapper type="glob" from="*.a" to="*.b"/>
<srcfile/>
<targetfile/>
</apply>
Take a look at Mapper type, too.
Try something like that for your case:
<target name="documentation" description="Generate Docco Documentation for coffee files">
<apply executable="docco" verbose="true" force="true" failonerror="true">
<srcfile />
<fileset dir ="${src.script.dir}" >
<include name="**/*.coffee"/>
</fileset>
<arg value="--output">
<mapper type="glob" from "*.coffee" to="*.html"/>
<targetfile/>
</apply>
</target>
I am running a foreach loop over all directories that are below a root directory.
I want to exclude all directories with the name "src" and "bin".
How can i exclude those directories from the results?
There are multiple subdirectories in the root directory and the subdirectories could also contain subdirectories. I want to go through all directories below the root, except those with the names above.
I have tried the following and none have worked:
<path>
<dirset dir="../Apps/">
<exclude name="*src*,*bin*"/>
</dirset>
</path>
<path>
<dirset dir="../Apps/">
<exclude name="**/src*,**/bin*"/>
</dirset>
</path>
<path>
<dirset dir="../Apps/">
<exclude name="**/src/**,**/bin/**"/>
</dirset>
</path>
This seems to work as expected (Ant 1.8.2 and ant-contrib 1.0b3) :
<target name="test">
<foreach target="echo-folder-name" param="folder">
<path>
<dirset dir="../Apps/">
<exclude name="**/bin/**" />
<exclude name="**/src/**" />
</dirset>
</path>
</foreach>
</target>
<target name="echo-folder-name">
<echo>${folder}</echo>
</target>
My application folder structure looks like this...
-js
-libs
-jquery.js
-jquery-ui.js
-app.js
-ui.js
I wish to concatenate the .js files that are in the /js directory but not those in the /js/libs directory. I am using the following code, but it is ignoring the exclude statement:
<concat destfile="${build.dir}/js/foot-${build.major}-${build.minor}.concat.js">
<fileset dir="${build.dir}/js">
<exclude name="**/libs/**" />
</fileset>
</concat>
The <fileset> should specify both include and exclude patterns. In addition, it may be good to specify a destination directory for <concat> separate from the <fileset> input directory.
<target name="concat-test">
<concat destfile="${basedir}/concat.js" fixlastline="yes">
<fileset dir="${basedir}/js">
<include name="**/*.js" />
<exclude name="**/libs/**" />
</fileset>
</concat>
</target>
I am trying to minify the css files in a directory and place the minified items into another directory. I already have:
<target name="css.minify">
<apply executable="java" parallel="false" force="true" dest="FDN/css/min">
<fileset dir="FDN/css" includes="**/*.css"/>
<arg value="-jar"/>
<arg path="lib/yuicompressor-2.4.7.jar"/>
<srcfile/>
<arg value="-o"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
</target>
This works fine when the directory structure in FDN/css/min is the same as FDN/css. However, if a new directory is added a FileNotFound occurs because it does not exist in the destination.
How can I force the directory to be created if it does not already exist?
You could create the dirs before you execute the apply task.
Here's an example of how you could do it:
<touch mkdirs="true">
<fileset dir="src">
<include name="**/*.css"/>
</fileset>
<regexpmapper from="^(.*)/[^/]*$$" to="dest/\1/.tmp" handledirsep="true"/>
</touch>
<delete>
<fileset dir="dest" includes="**/.tmp"/>
</delete>
It's based on an answer I gave to a different question.