Kliver Max
Kliver Max

Reputation: 5299

How to rename files in batch file?

In folder i have a files with names:

66-1-194-111-F.tiff
66-1-194-111-F.tab
66-1-194-111-F.tfw

66-1-194-111-R.tiff
66-1-194-111-R.tab
66-1-194-111-R.tfw

66-1-194-111-G.tiff
66-1-194-111-G.tab
66-1-194-111-G.tfw
****

66-1-194-111 can be changed. I want to rename this files. If last symbol in name if F i want to set file name 66-1-194-111-Q. If R i want set file name is 66-1-194-111-W...

How to rename files with this if statement?

Upvotes: 0

Views: 198

Answers (1)

MC ND
MC ND

Reputation: 70941

It the files are named as shown,

ren "*-F.*" "*-Q.*"

Just be sure to do the rename in the adecuate order to not mix different sets of files.

For an "automated" way, you can adapt this

@echo off
    setlocal enableextensions

    for %%a in ( "F Q" "R W" ) do for /f "tokens=1,2" %%b in (%%a) do (
        echo ren "*-%%b.*" "*-%%c.*"
    )

    endlocal

Note that the ren line is only echoed to console. If output is correct, remove echo to rename the files.

Upvotes: 3

Related Questions