Sample Header Ad - 728x90

Paste files with the same names from directories and subdirectories to another directory

1 vote
1 answer
47 views
I'm looking for a way to paste files with the same names, contained in directories and subdirectories, to another directory with the same subdirectory structure. For instance :
Dir1/a/a/file1
Dir2/a/a/file1
Those would be pasted into this directory :
Dir3/a/a/file1
Now I found on stackexchange a piece of zsh code that I modified to get the following :
#!/bin/zsh

typeset -A files
for file (dir*/*/*/*(nN)) files[$file:t]+=$file$'\0'
for file (${(k)files}) paste -d "\0" ${(0)files[$file]} > outputDir/*/*/$file
This doesn't work, as the code doesn't understand the "*" after outputDir. If I set a precise set of subdirectories for instance ouputDir/a/a/$file it works like a charm. I don't really know zsh as I discovered it with this piece of code. How could I do to keep the same subdirectories structure for the output dir ? Thank you for your help. Regards
Asked by Mathias Paicheler (11 rep)
Mar 17, 2023, 04:58 PM
Last activity: Mar 19, 2023, 12:12 PM