0
votes

How can I reverse the directory structure for files using Ant.

For example, I have the following

C:\some\path\a\b\file1.txt
C:\some\path\y\z\file2.txt

I would like to convert this to

C:\some\dir\b\a\file1.txt
C:\some\dir\z\y\file2.txt

In terms of variables in Ant, I know C:\some\path and C:\some\dir, but I don't know the directories a,b,y,z (those are entirely dynamic).

Ideally it would to be a separate directory (e.g. from path -> dir), but in-place is OK to since I can just copy elsewhere first.

I thought globmatcher/regexmatcher might help, but I think they only change the file name, not the directory name.

1

1 Answers

0
votes

There is actually a somewhat relevant sample in the ant docs for mapper

Just use the regex mapper during the move or copy and reverse the directory order in the match:

<mapper type="regexp" from="^(.*)/([^/]+)/([^/]*)$$" to="\2/\1/-\3"/>