2012-12-27 57 views
2


我有批處理腳本的這一部分這是做如下:
-there是一個主文件夾,主文件夾中有兩個文件(電影&字幕文件)和一個名爲「字幕」的子文件夾

- 此腳本取得電影文件的名稱並用它重命名字幕文件+將字幕文件移動到「字幕」子文件夾中,然後重命名主夾。所以最後我們有一個電影名稱,它也用在字幕文件和主文件夾上。

如何根據通過批處理腳本他的文件夾名稱重命名文件

@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 

!!!!!我需要的是以下內容:!!!!!
- 我需要讓反之亦然,所以名稱將從主文件夾取,而不是從電影文件,因此主文件夾的名字將在電影上使用字幕文件

謝謝!

回答

3
@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 
+0

:))這是你。再次感謝你!它工作,因爲它應該工作! – user1868774

相關問題