多くのサブディレクトリにたくさんのファイルがあります。Bash:再帰的にサブディレクトリを再作成
私はそれらに対していくつかのタスクを実行し、結果を新しいファイルで返しますが、入力とまったく同じサブディレクトリを持つ出力ディレクトリに戻したいと思います。
私はこのすでに試してみてください。
#!/bin/bash
########################################################
# $1 = "../benchmarks/k"
# $2 = Output Folder;
# $3 = Path to access the solver
InputFolder=$1;
OutputFolder=$2;
Solver=$3
mkdir -p $2;
########################################
#
# Send the command on the cluster
# to run the solver on the instancee.
#
########################################
solveInstance() {
instance=$1;
# $3 $instance > $2/$i.out
}
########################################
#
# Loop on benchmarks folders recursively
#
########################################
loop_folder_recurse() {
for i in "$1"/*;
do
if [ -d "$i" ]; then
echo "dir: $i"
mkdir -p "$2/$i";
loop_folder_recurse "$i"
elif [ -f "$i" ]; then
solveInstance "$i"
fi
done
}
########################################
#
# Main of the Bash script.
#
########################################
echo "Dir: $1";
loop_folder_recurse $1
########################################################
問題は私のラインmkdir -p "$2/$i";
です。 $2
は最初に作成するディレクトリの名前なので、問題はありません。しかし、$i
では絶対パスにすることができ、その場合、ファイルに到着するすべてのサブディレクトリを作成する必要があります。不可能です。それとも、それは..
と表示され、問題の同じ種類...私はこのバグを修正する方法を正確に知らない
を含めることができます/私はsed
といくつかのことをしようとしたが、私は成功しませんでした:/
'find -exec'の使用を検討してください。 –
あなたが '../../../dir1'のようなパスを' $ i'の 'dir1'でちょうど作成したいのであれば、それは私の問題です。 – Inian
です。私は$ ouput/dir1/ –