Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy content of subfolders with Ant

Tags:

copy

ant

fileset

How can I copy content of all subfolders of given folder using Ant?

i.e. I have such folder structure

folder/
folder/sub1/1.txt
folder/sub1/f1/1.txt
folder/sub2/2.txt
...

I don't know exact names of subfolders. And I need to copy content from all of them into one folder (keeping the structure of content, i.e. copying all files into one dir using flatten isn't a solution). I need to get

newfolder/1.txt
newfolder/1/1.txt
newfolder/2.txt
...

Does fileset allows to group subfolders in such a way? ** stands for zero or more directories, and usage of * as directory name is disallowed, i.e. <fileset dir="${dir}/*/" /> isn't acceptable.

Thanks in advance, Yury

like image 986
Yury Khrol Avatar asked Aug 06 '10 12:08

Yury Khrol


People also ask

How do I copy a file from multiple subfolders to one directory in Linux?

To copy multiple files with the “cp” command, navigate the terminal to the directory where files are saved and then run the “cp” command with the file names you want to copy and the destination path. Above mentioned scenarios are how to copy a single or selected file in a directory.


1 Answers

<copy toDir="newfolder">
  <fileset dir="folder">
    <include name="*/**"/>
    <exclude name="*"/>
  </fileset>
  <regexpmapper from="^[^/]*/(.*)$$" to="\1" handledirsep="true"/>
</copy>

You only need to specify handledirsep if you ever intend to run this script in Windows.

like image 193
Alexander Pogrebnyak Avatar answered Oct 24 '22 11:10

Alexander Pogrebnyak