I have a very large directory structure of source code that is very difficult to work with. I would like to run a tool to transform it to a Maven like structure that works better for me. When I have finished my work I run the tool again to transform the Maven structure back to the original awful structure. I am very familiar with various shells and yes I could write a script containing hundreds of cp commands. But this will be hard to maintain.
I want to be able to move or copy files using something like Perforce's triple dot wild card that:
Matches all files under the current working directory and all subdirectories. (matches anything, including slashes, and does so across subdirectories)
My script would then contain commands like:
cp src/.../foobar/.../*.java trusted/src/main/java/.../foobar/.../*.java
The idea is to move a subtree of the directory while maintaining the structure of that subtree.
Any ideas?
I am having issues with the Gilles' rsync solution. Here is a test script:
#!/bin/bash
rm -rf source
mkdir -p source/server/src/com/bodhi/foobar/this
mkdir -p source/server/src/com/bodhi/foobar/that
mkdir -p source/server/src/com/bodhi/other
echo "Hello World" > source/server/src/com/bodhi/foobar/this/A.java
echo "Hello World" > source/server/src/com/bodhi/foobar/that/B.java
echo "Hello World" > source/server/src/com/bodhi/other/C.java
rm -rf target
mkdir -p target/foobar/src/main/java
rsync \
--include='**/foobar/**/*.java' \
--include='**/foobar/**/' \
--exclude='*' \
--prune-empty-dirs \
source/server/src/ target/foobar/src/main/java/