How to exclude all sub-folders in the directory using fileset? - jenkins

I have an ANTScript like:
<fileset dir="${sqlDirectory}" >
<include name="**/*.sql"/>
<exclude name="**/back_out/**"/>
</fileset>
I am trying to exclude all sub-folders in the directory. The above code excludes only back_out subfolder.
Is it possible to exclude any sub-folders inside the directory?

Here is the solution which I have found:
<fileset dir="${sqlDirectory}" >
<include name="**/*.sql"/>
<exclude name="*/**/*" />
</fileset>

Related

How to copy a files to a particular dir using ant?

i need to copy test.bat into the bin folder
i worte a code in build.xml such that it should copy a file from bin/test.bat to dist/intall/windows/
but it not copying
project structure
project
|-dist-install-windows-bin
|-etc-bin-test.bat
|-src-build.xml
<target name="copy">
<copy todir="./dist/install/windows/bin">
<fileset dir=".">
<include name="etc/bin/test.bat"/>
</fileset>
</copy>
</target>
Give parent directory as "dir" attribute
<fileset dir="..">
<include name="etc/bin/test.bat"/>
</fileset>

Ant to delete subdirectories and files in subdirectories but not any file from the directory itself

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>

Delete fileset filenames, but in different directory

So I have a fileset containing files in one directory:
<fileset id="modules" dir="${modules.dir}">
<include name="core*.jar"/>
<include name="fileset*.jar"/>
<include name="upgrader*.jar"/>
<include name="hello*.jar"/>
</fileset>
However, these files are copied into the ${lib.dir}, i.e, the ${lib.dir} contains copies of core*.jar, fileset*.jar, etc.
How do I delete these copied files?
Also, please note I can't use external libraries like ant-contrib.
Use a PatternSet to define the set of names. Then reference that PatternSet in any number of FileSets.
<patternset id="module.patterns">
<include name="core*.jar"/>
<include name="fileset*.jar"/>
<include name="upgrader*.jar"/>
<include name="hello*.jar"/>
</patternset>
<fileset id="modules" dir="${modules.dir}" >
<patternset refid="module.patterns"/>
</fileset>
UPDATE:
Given your comment that you want only the original files, try this:
<pathconvert pathsep="," property="flattened.modules" refid="modules">
<mapper type="flatten" />
</pathconvert>
<filelist id="libmodules" dir="${lib.dir}" files="${flattened.modules}"/>

Ant concat exclude directory

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>

Ant - copy only file not directory

I need to copy all files in a folder except directory in that folder using Ant script.
Im using below script to do that.
<copy todir="targetsir">
<fileset dir="srcdir">
<include name="**/*.*"/>
</fileset>
</copy>
But it copies all files and directory in that folder.
how to restrict/filter directory in that folder?
thanks,
I think there is an easier way.
flatten="true" - Ignore directory structure of source directory, copy all files into a single directory, specified by the todir attribute. The default is false.
Do you mean that srcdir conatins sub-directories, and you you don't want to copy them, you just want to copy the files one level beneath srcdir?
<copy todir="targetsir">
<fileset dir="srcdir">
<include name="*"/>
<type type="file"/>
</fileset>
</copy>
That should work. The "**/*.*" in your question means "every file under every sub directory". Just using "*" will just match the files under srcdir, not subdirectories.
Edited to exclude creation of empty subdirectories.
I do not have enough reputation to comment, so I'm writing new post here. Both solutions to include name="*" or name="*.*" work fine in general, but none of them is exactly what you might expect.
The first creates empty directories that are present in the source directory, since * matches the directory name as well. *.* works mostly because a convention that files have extension and directories not, but if you name your directory my.dir, this wildcard will create an empty directory with this name as well.
To do it properly, you can leverage the <type /> selector that <fileset /> accepts:
<copy todir="targetsir">
<fileset dir="srcdir">
<include name="*"/>
<type type="file"/>
</fileset>
</copy>
Can you try
<copy todir="targetsir">
<fileset dir="srcdir">
<include name="*.*"/>
</fileset>
</copy>
** is used to match a directory structure.
<copy todir="targetsir" includeEmptyDirs="false">
<fileset dir="srcdir">
<include name="*"/>
</fileset>
</copy>
If your folder has many subdirectories and you don't want them to be copied (if you want only files) try this..
<target name="copy">
<copy todir="out" flatten="true">
<fileset dir="tn">
<filename name="**/cit.txt" />
</fileset>
</copy>
</target>
The secret is to use not fileset but dirset instead.

Resources