From: Gauthier Bouilhol Date: Wed, 28 Sep 2011 16:56:42 +0000 (+0200) Subject: sorted directory is put outside the original one X-Git-Tag: v1.3.0~213^2 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=160997ac5da8a87f6f0aa53fead2fe434844e2ad;p=clitk.git sorted directory is put outside the original one --- diff --git a/scripts/dcm_sort_by_field.sh b/scripts/dcm_sort_by_field.sh index 44dba59..81d1b6b 100755 --- a/scripts/dcm_sort_by_field.sh +++ b/scripts/dcm_sort_by_field.sh @@ -4,12 +4,14 @@ then echo Usage: dcm_sort_by_field.sh \"field name\" exit fi -[ -d sorted ] && rm -r sorted -find . -type f -iname "*.dcm" > dicom_files +path_dir=`pwd` +dir_name=`basename "$path_dir"` +[ -d "../${dir_name}_sorted" ] && rm -r "../${dir_name}_sorted" +mkdir "../${dir_name}_sorted" +find . -type f -iname "*.dcm" > ../${dir_name}_sorted/dicom_files finished=0 -total=$(wc -l dicom_files) -mkdir sorted -cat dicom_files | while : +total=$(wc -l ../${dir_name}_sorted/dicom_files) +cat ../${dir_name}_sorted/dicom_files | while : do jobrunning=0 conc_jobs=50 @@ -18,14 +20,14 @@ do read i || { wait; break 2; } { name="$(clitkDicomInfo "$i" | grep "$1" | head -n 1 | sed "s/.*\[//;s/.$//;s/ /_/g")" - [ -z "$name" ] && echo "Warning: key not found in file $i" 1>&2 && mkdir -p unsorted && basename=$(basename "$i") && cp -l "$i" "unsorted/$basename" && exit 1 #copy to unsorted directory if dicom key not found + [ -z "$name" ] && echo "Warning: key not found in file $i" 1>&2 && mkdir -p "../${dir_name}_unsorted" && basename=$(basename "$i") && cp -l "$i" "../${dir_name}_unsorted/$basename" && exit 1 #copy to unsorted directory if dicom key not found #[ -z "$name" ] && echo "Warning: key not found in file $i" 1>&2 && exit 1 #don't do anything if dicom key not found name=`echo "$name" | sed 's/\//_/g'` name=`echo "$name" | sed 's/\\\/_/g'` name=`echo "$name" | sed 's/\*/_/g'` - [ -d "sorted/$name" ] || mkdir "sorted/$name" 2>>/dev/null + [ -d "../${dir_name}_sorted/$name" ] || mkdir "../${dir_name}_sorted/$name" 2>>/dev/null basename=$(basename "$i") - cp -l "$i" "sorted/$name/$basename" + cp -l "$i" "../${dir_name}_sorted/$name/$basename" }& jobrunning=$(( $jobrunning + 1 )) done @@ -33,4 +35,4 @@ do echo -e -n "( $finished / $total )\r" wait done -rm dicom_files +rm ../${dir_name}_sorted/dicom_files