Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

批量重命名(含空格的文件) #13

Open
Windy147 opened this issue Apr 17, 2024 · 0 comments
Open

批量重命名(含空格的文件) #13

Windy147 opened this issue Apr 17, 2024 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@Windy147
Copy link
Owner

#!/bin/bash

folder_path="./"
# 进入文件夹
cd "$folder_path" || exit

# 获取文件夹下所有的.mp4文件,并按照字母顺序排序
mp4_files=(*.mp4)
IFS=$'\n' mp4_files=($(sort -t 'P' -k 2n<<<"${mp4_files[*]}"))
unset IFS

# 初始化计数器
counter=1

# 逐个重命名文件
for file in "${mp4_files[@]}"; do
    # 新文件名
    new_name="video_${counter}.mp4"
    # 重命名文件
    mv -- "$file" "$new_name"
    # 计数器递增
    ((counter++))
done


@Windy147 Windy147 added the documentation Improvements or additions to documentation label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant