I want to copy a list of files, called dti_fin_fa
, from one folder to another.
These files are scattered in different folders.
Controls
└───C01
│ └───difusion
│ └───Deterministic
│ └───dti_fin_fa.nii
└───C02
│ └───difusion
│ └───Deterministic
│ └───dti_fin_fa.nii
└───C03
│ └───difusion
│ └───Deterministic
│ └───dti_fin_fa.nii
I want to select and copy all the dti_fin_fa
, keeping the folder structure, so, in my new directory, I would have the folder distribution just seen above. The problem is that in this folders, (deterministic
, difusion
, etc), there are lots of other files I don´t want to copy, so I can´t just copy the main folder (C01
etc)
This is what I have:
#!/bin/bash
DIR="/media/Batty/Analysis"; cd "$DIR" || exit
for group in Controls; do
for folder in $group/*; do
for dti in $folder/difussion/Deterministic/dti_fin_fa.nii; do
echo $dti
cp $dti /media/Roy/Analysis/Controls/ --verbose
done;
done;
done;
The problem is that this code copies each of the dti_fin_fa.nii
images into /media/Roy/Analysis/Controls/
, hence keeping just the last one, instead of creating all the other subfolders.
Could something like this work?
cp $folder/difusion/Deterministic/$dti /media/Roy/Analysis/Patients/ --verbose