In a nutshell, using Ant, I can't seem to figure out copying everything in a directory to another directory, while excluding a certain subdirectory in the source, or originating, directory. In other words, if I have the following directory structure
I'd like to copy everything inside the origin directory to a destination directory, excluding subdirectory1, such that the contents of the destination directory would look like
Note that the origin directory might dynamically contain many other subdirectories and files that I'd also want copied. The subdirectory that I don't want copied is always known. I can only seem to figure out copying everything over. I realize I could just copy everything and then delete what's not wanted, but that seems silly. I figured I'd surely be able to figure out specifying a fileset to exclude certain subdirectories, but I can't. I was hoping that the following fileset would work, but it doesn't - it just includes everything, including the excluded subdirectory. Any ideas?
I thought the "**" part of paths meant that it would match any depth of directory. So, <exclude name="**/directory/*"/> would actually exclude all directories "named directory" in ANY subdirectory of the outer fileset dir attribute's value. So, <exclude name="directory/**/*"/> would exclude all files and subdirectories of only one directory (directory). I'm not sure about that leading slash though. I don't think it should be there. Also, I'm not sure if the extra "/*" is needed here.
Leave out the beginning ** and / from your include and exclude
Leave the training ** but no /* on your exclude
If you have <exclude name=something/**/*"/> it will include the directory "something" though it will be empty. With just <exclude name="something/**"/> it will not be there at all. You definitely don't want the beginning ** (my other post explains).
Joined: Dec 10, 2001
You are right, of course. Thank you for the correction. Now, for what I'd actually like to be doing. I'd prefer to exclude a directory from the fileset, where I know the absolute directory location, but I don't necessarily know just the name of the directory. As previously described, this directory is a subdirectory of the origin directory. Currently, I use a properties file to specify both the absolute directory location, which is used in one part of my Ant script, and to specify the relative location, which is used only to be certain to exclude it from the fileset I'm trying to build as explained from the beginning of this thread. I'd really prefer to just specify the absolute location in the properties file. Any ideas?
Joined: May 29, 2003
Dirk, I may be misunderstanding part/all of what you said. But why not just do:
If you're asking if you can combine the full absolute path into one <exclude> then I don't think you can do that, as the fileset requires a "dir" attribute, with the nested "exclude"s that list subdirectories/files to exclude and so forth. So, it really does require two properties. Did any of this help? Or am I way off?
Joined: Dec 10, 2001
I'd like to exclude a known absolute directory from a fileset, in order to reduce the number of properties I'm carrying around. It appears that I can't do this with an exclude in a fileset. Thanks for the confirmation, Nathaniel.