批量替换同名文件

#!/bin/bash

root_dir1="/Users/butter/Documents/shiritan/shiritan/pdf.xcassets"  #xcode
root_dir2="/Users/butter/Desktop/ziyuan"  #资源包

function getdir(){
echo '路径1' $1

for element in `ls $1`
do
dir_or_file=$1"/"$element
if [ -d $dir_or_file ]
then
getdir $dir_or_file
else
#echo $element
#echo $dir_or_file
#############################第二层循环
for element1 in `ls $root_dir2`
do
dir_or_file1=$root_dir2"/"$element1
if [ $element = $element1 ]
then
echo "文件名字相等 开始移动"
#echo $element
#echo $dir_or_file
#echo $element1
#echo $dir_or_file1
rm $dir_or_file
mv $dir_or_file1 $1
echo "完成"

else
echo "不相等"
#echo $element
#echo $dir_or_file
#echo $element1
#echo $dir_or_file1
fi
done
###############################
fi
done
}

getdir $root_dir1

你可能感兴趣的:(批量替换同名文件)