views:

22

answers:

1

Hi there,

I am trying to write a script (preferably in bash) to flatten a java projet directory structure prepending the path to the file. Example:

| src
  | org
    | apache
      | file2.java
    | file1.java

would result in:

| src
  | org|apache|file2.java
  | org|file1.java

The script should be recursive since the directory could have many subfolders.

+1  A: 
cd src
for i in $(find . - name '*.java') ; do 
  echo cp \"$i\" $(echo "$i" | tr / _)
done

if it looks good(might barf if filenames contains spaces), pipe the result to sh

nos
Is it possible for a java file name to have spaces?
Fork
By the way, when i Removed the first echo and the quotes from the $i variable and ran the script it didn't do anything.
Fork
I have gotten it to work.
Fork
`find ... | while read -r i` instead of `for ... find` will work if filenames have spaces.
Dennis Williamson
How would I adapt to your solution?
Fork