gpt4 book ai didi

batch-file - 如何通过批处理脚本根据文件夹名称重命名文件

转载 作者:行者123 更新时间:2023-12-04 05:17:40 27 4
gpt4 key购买 nike

我有批处理脚本的这一部分,它正在执行以下操作:
- 有一个主文件夹,主文件夹中有两个文件(电影和字幕文件)和一个名为“字幕”的子文件夹
- 此脚本采用电影文件的名称并用它重命名字幕文件 + 将字幕文件移动到“字幕”子文件夹中,然后重命名主文件夹。所以最后我们有一个电影名称,用于字幕文件和主文件夹。

@echo off
setlocal EnableDelayedExpansion


cd /D "%~DP0"
echo BASE FOLDER: %cd%
set n=0
for /D %%a in (*) do (
set /A n+=1
cd "%%a"
echo ==================================================================
echo Processing folder: %%a


for %%b in (*.avi *.mp4 *.mkv) do set movieName=%%~Nb
echo Movie name: !movieName!
for %%b in (*.srt *.sub) do (
move "%%b" "Subtitles\!movieName!%%~Xb"
echo File "%%b" moved and renamed to "Subtitles\!movieName!%%~Xb"
)


cd ..
ren "%%a" "!movieName!"
echo Folder "%%a" renamed to "!movieName!"

)
echo ==================================================================
echo %n% FOLDERS PROCESSED
pause

!!!!!!我需要的是以下内容:!!!!!!
- 我需要把它反过来 ,所以 名称将取自主文件夹 而不是来自电影文件,所以 主文件夹的名称将用于电影和字幕文件 .谢谢!

最佳答案

@echo off
setlocal EnableDelayedExpansion


cd /D "%~DP0"
echo BASE FOLDER: %cd%
set n=0
for /D %%a in (*) do (
set /A n+=1
cd "%%a"
echo ==================================================================
echo Processing folder: %%a
set movieName=%%~a


for %%b in (*.avi *.mp4 *.mkv) do (
ren "%%~b" "!movieName!%%~Xb"
echo Movie file "%%b" renamed to "!movieName!%%~Xb"
)

for %%b in (*.srt *.sub) do (
move "%%~b" "Subtitles\!movieName!%%~Xb"
echo File "%%b" moved and renamed to "Subtitles\!movieName!%%~Xb"
)


cd ..

)
echo ==================================================================
echo %n% FOLDERS PROCESSED
pause

关于batch-file - 如何通过批处理脚本根据文件夹名称重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14055495/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com