.bat rename files name remove first x characters and last x characters

后端 未结 1 1150
星月不相逢
星月不相逢 2021-01-14 14:50

I need to rename files in some folder, like explained it needs to rename file names in one folder by removing first number of x characters and last number of x characters I

1条回答
  •  伪装坚强ぢ
    2021-01-14 15:29

    Here you go:

    @echo off
    setlocal enabledelayedexpansion
    set X=3
    set FOLDER_PATH=.
    pushd %FOLDER_PATH%
    for %%f in (*) do if %%f neq %~nx0 (
        set "filename=%%~nf"
        set "filename=!filename:~%X%,-%X%!"
        ren "%%f" "!filename!%%~xf"
    )
    popd
    

    This script enters the folder (specified by FOLDER_PATH) and trims the first and last X characters from the filename of each file (leaving its extension as is). Modify X and FOLDER_PATH as necessary.

    0 讨论(0)
提交回复
热议问题