Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ant - copy dir, exclude subdir

 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aha!
exclude name="**/subdirectory1/**" seems to work.
[ April 19, 2004: Message edited by: Dirk Schreckmann ]
 
Sadanand Murthy
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Dirk Schreckmann:
Aha!
exclude name="**/subdirectory1/**" seems to work.
[ April 19, 2004: Message edited by: Dirk Schreckmann ]

I believe you can omit the last 2 asterisks:
exclude name="**/subdirectory1/" should also work.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now for my correction:

You need to:
  • 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).
     
    Dirk Schreckmann
    Sheriff
    Posts: 7023
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    Nathaniel Stoddard
    Ranch Hand
    Posts: 1258
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    Dirk Schreckmann
    Sheriff
    Posts: 7023
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic