I have numerous txt
files, scattered across different folders.
- case1
|
- 0.25
|
- case1.txt
- 0.35
|
_ case1.txt
- 0.30
|
_ case1.txt
- 0.45
|
_ case1.txt
- case2
|
- 0.25
|
- case2.txt
- 0.35
|
_ case2.txt
- 0.30
|
_ case2.txt
- 0.45
|
_ case2.txt
.
.
.
I would like to copy them all to a folder, but unfortunately, as you can see, some of them have the same name, and thus a naive find
solution ends up overwriting them. I would like to copy all the txt
files to a directory foo
, inserting the name of the name of the subfolder they're in, before the .txt
extension. Also, since that the subfolder has a dot in the name, and I need to copy these files to Windows, I'd also like to change 0.25
to 0_25
. In other words, the file
- case2
|
- 0.25
|
- case2.txt
must be copied to foo
as case2_0_25.txt
. If a bash solution is too complex/unreadable, a Python solution would be fine too, but not a zsh one.