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>
Related
How do I copy only files immediately under the directory and not its subdirectories? I don't know a priori the names of the files or the subdirectories. I've tried the following to no avail:
<include name="*"> # includes all files and subdirs
===
<include name="*">
<exclude name="*/**> # or "*/" or "**"
Any help would be appreciated.
UPDATE:
I ended up just adding a delete task to delete the copied subdirectories:
<delete includeemptydirs="true">
<fileset dir="${targetdir}">
<type type="dir"/>
</fileset>
</delete>
<?xml version="1.0" encoding="UTF-8"?>
<project default="copy-top-most-files-only" name="My Project">
<property name="to.dir" value="/path/to/dest/folder/" />
<property name="from.dir" value="/path/to/source/folder/" />
<target name="copy-top-most-files-only">
<copy todir="${to.dir}" includeEmptyDirs="false" >
<fileset dir="${from.dir}">
<exclude name="*/**/*" />
</fileset>
</copy>
</target>
</project>
One way to do this is to specify a <depth> selector, for example:
<copy todir="dest">
<fileset dir="src">
<depth max="0" />
</fileset>
</copy>
That will prevent subdirectories from being copied.
You can combine selectors with include/exclude rules if needed.
I need to create a fileset but I need to exclude a folder if some property is set (project.name).
<fileset dir="${build.folder}">
<include name="**/*"/>
<exclude name="${project.name}/**/*"/>
</fileset>
How can I do it?
Assuming you are using a recent version of ANT (1.9.1+), try this:
<project name="tryit" xmlns:if="ant:if" xmlns:unless="ant:unless">
<target name="try">
<fileset id="my-fileset" dir="${build.folder}">
<include name="**/*"/>
<exclude if:set="project.name" name="${project.name}/**/*"/>
</fileset>
<echo message="My fileset is ${toString:my-fileset}" />
</target>
</project>
My requirement is to delete all subdirectories from a specified directory, but NOT delete files in the specified directory.
I have fussed around with fileset and dirset and I could not get a single collection to do the job. What works is this:
<delete includeemptydirs="true" verbose="true" >
<fileset dir="release/reports" >
<exclude name="*.*" />
</fileset>
<dirset dir="release/reports" includes="**/*" />
</delete>
Isn't there a way to do this with one collection (either fileset or dirset)?
It should work like that :
<delete includeEmptyDirs="true">
<fileset dir="C:/yourdir" includes="**/*" excludes="*.*"/>
</delete>
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.
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>