[shell/脚本]检索某个文件夹下的所有文件夹并且复制文件夹下文件到指定目录

写一个脚本实现不同分支下的代码sync
递归去检索某个文件下的所有文件

#!/bin/bash

#usage:
#source sync_code.sh (源码路径) (目标路径)

SOURCEDIR=$1
TARGETDIR=$2

if [ ! -d $SOURCEDIR ] || [ ! -d $TARGETDIR ] ; then
        echo "Input path is not exist!"
fi

function is_ready(){
	sou_dir=$1
	tar_dir=$2
	if [ ! -d $sou_dir ] || [ ! -d $tar_dir ] ; then
        echo "The paths do not exist or the two do not match!"
	else
		#该方法不完全可取 因为文件夹下存在make.inc
		#cd $sou_dir
		#cp -fp `ls |grep -v data|xargs`
		#cd $tar_dir
		#find -name *.inc |xargs rm -rf

		if ls $sou_dir/*.h >/dev/null 2>&1;then
			#echo "this path exit target_file *.h"
			cp -fp $sou_dir/*.h $tar_dir/
		else
			echo "this path does not exit target_file *.h"
		fi

		if ls $sou_dir/*.c >/dev/null 2>&1;then
			#echo "this path exit target_file *.c"
			cp -fp $sou_dir/*.c $tar_dir/
		else
			echo "this path does not exit target_file *.c"
		fi
		
		#可以手动添加其他格式的文件
	fi
}

function cp_file(){
	sou_dir=$1
	tar_dir=`echo ${sou_dir} |sed "s?${SOURCEDIR}?${TARGETDIR}?g"`
	echo $tar_dir
	echo $sou_dir
	is_ready $sou_dir $tar_dir
}

function dir_list(){
	for file in $1
		do
			if [ -d "$file" ] 
			then
				cp_file $file
				dir_list $file"/*"
			fi
		done
}

dir_list $SOURCEDIR
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值