]> Creatis software - clitk.git/commitdiff
sorted directory is put outside the original one
authorGauthier Bouilhol <bouilhol@creatis.insa-lyon.fr>
Wed, 28 Sep 2011 16:56:42 +0000 (18:56 +0200)
committerGauthier Bouilhol <bouilhol@creatis.insa-lyon.fr>
Wed, 28 Sep 2011 16:56:42 +0000 (18:56 +0200)
scripts/dcm_sort_by_field.sh

index 44dba5980643a1f06818dc5be68f7ad175c88fda..81d1b6b8d5f1214b737b8b2d5a0d7b1335e6e2aa 100755 (executable)
@@ -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