I’d like to copy files and subdirectories using Ant from a single subdirectory without copying the rest of the directory structure and contents. For example, I’d like to copy dir_3, its files (file_1 to file_n) and subdirectories (dir_4 and dir_5), but not dir_1 nor dir_2. Is there a pattern that I can use to do this?
temp
\--dir_1
\--dir_2
|
\--dir_3
|
\--dir_4
\--dir_5
\-- file_1
|
\--file_n
Thanks.
When you use the
includedirective, it will only include the files that match the pattern you give it. In this case, I’m copying only those files that have/dir3/somewhere in their full path name. This includes sub-directories underdir3and all files underdir3.You can use the
excludedirective to override theincludedirectives:This will copy all sub-directories and files in those sub directories, but not the files under
dir3itself. The*matches all files in the directory while**matches the all the files in the entire directory tree.Notice this will create a directory
temp/dir2/dir3. If I wanttemp/dir3, I have to set my fileset to the parent directory ofdir3:Doing this:
Will create a directory
tempwith all the files directly underdir3directly undertemp. There will also be atemp/dir4andtemp/dir5directory containing all the files (and directory trees) under those directories.