sh 重命名文件夹中的文件以匹配文件夹名称(对于htpc用法很有用)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 重命名文件夹中的文件以匹配文件夹名称(对于htpc用法很有用)相关的知识,希望对你有一定的参考价值。

#!/bin/bash
# SYPOPSIS: Rename files in folder to match folder.
# CREDIT: Unamed user on superuser or superadmin. If you find this, let me know and I will add you to the credits.
# UPCOMING: Allow for secondary input such as `rename-files-to-folder $MOVIENAME` so not to rename all movies in directory just one or two.

find * -type f -maxdepth 1 | while read file
do
    dirname="$(dirname "$file")"
    new_name="${dirname##*/}"
    file_ext=${file##*.}
    if [ -n "$file_ext" -a  -n "$dirname" -a -n "$new_name" ]
    then
        echo "mv '$file' '$dirname/$new_name.$file_ext'"
    fi
done

以上是关于sh 重命名文件夹中的文件以匹配文件夹名称(对于htpc用法很有用)的主要内容,如果未能解决你的问题,请参考以下文章