LINUX下,用脚本处理一个目录所有文件的代码

  文件convert-dir.sh


ROOT_DIR=/media/quantum6/disk/SOFTWARE/videos/wuxi
CONVERT_H264=/home/quantum6/Develop/videos/convert_to_h264_by_nv.sh

cd $ROOT_DIR

# 只列出目录
for path in $(ls -d *)
do
    # 检测是否目录 在次基础上进行递归处理。
    full_path=$ROOT_DIR/$path
    if [ -d $full_path ] ; then
        echo $full_path
    fi

    cp $CONVERT_H264 $full_path
    cd $full_path

    # 只列出文件
    for file in $(ls -f *)
    do
        # 检查是否文件
        # if [ -f $file ] ; then

        # 以converted-开头的不处理
        if [[ ${file:0:10} = "converted-" ]] ; then
            echo converted
            continue
        fi

        # 以h264结尾的不处理
        if [ "${file##*.}" = "h264" ]; then
            echo h264
            continue
        fi

        # 这个文件已经转换过了
        confile=converted-$file.h264
        if [ -f $confile ] ; then
            echo has converted $file
            continue;
        fi

        # 这些才处理。
        echo process $file
        ./convert_to_h264_by_nv.sh $file

    done
done

  同目录下有文件convert_to_h264_by_nv.sh。

  子目录是wuxi,执行:

convert-dir.sh wuxi

猜你喜欢

转载自blog.csdn.net/quantum7/article/details/82714543