模拟dos中的xcopy功能,实现文件的复制,当子文件夹不存在时自动创建

#!/bin/sh

# 模拟dos中的xcopy功能,实现文件的复制,当子文件夹不存在时自动创建
movefile()
{
    local file=$1
    local destDir=$2
    echo file=$file
    echo destDir=$destDir
    # 
    local len=`expr length $projectAbsltPath` # ¹¤³Ì·¾¶È·¶¨ºó£¬²»»áµ÷Õû 
    cd `dirname $file`    					# »ñÈ¡ÊäÈëÎļþµÄ·¾¶£¬Ã¿¸öÎļþµÄ·¾¶¾ù¿ÉÄÜ´æÔÚ²îÒì
    local fileAbsltPath=`pwd`
    cd - >& /dev/null 
    local fileRelPath=`eval echo ${fileAbsltPath:${len}}` 	# »ñÈ¡Ïà¶Ô·¾¶ 20110510
    fileRelPath1=`eval echo .${fileRelPath}/`  		# È¥µôµÚÒ»¸ö×Ö·ûб¸Ü'/' 
    #echo ==fileRelPath1=$fileRelPath1    
    cd ${destDir}
    mkdir -p ${fileRelPath1}
    cd - >& /dev/null  
    #echo ${destDir}/${fileRelPath1} 
    mv ${file} ${destDir}/${fileRelPath1}
}

#############################################################################################
projectAbsltPath=`pwd`

movefile $1 $2


 

你可能感兴趣的:(dos,File)