How to rename a file according his folder name via batch script

后端 未结 1 1241
小蘑菇
小蘑菇 2021-01-21 23:24


I have this part of batch script which is doing following:
-There is a main folder, in the main folder are two files (movie & subtitle file) and one Sub-fo

1条回答
  •  时光说笑
    2021-01-21 23:49

    @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 讨论(0)
提交回复
热议问题