Batch application: Rename according to the file content

Time:2021-10-25

I want to achieve the following objectives:
First, I have a. Dat file with a fixed name. I need to change the file name
. dat line 1 reads:   10107xxxxx means January 1, 2007. The following x is not fixed. If it is from January to September, the first character is empty
Now change the file name according to this line. For example, 10107xxxxxx is changed to c01-0101.cvs
110107xxxxx, changed to c01-1101.cvs
Please tell me how to write this bat file

analysis:
Read the first line to a variable
The fifth character of the area variable, which can determine whether it is 0  
1) If it is 0, the first 2 digits of the variable are taken as the month; otherwise, the first 1 digits are taken and prefixed with 0 as the month
2) If it is 0, take 3-4 digits of the variable as the month, otherwise take 2-3 digits as the day

answer:
@echo off
for %%i in (*.dat) do call :goren %%i
goto end

:goren
set /p firstln=<%1
set year=%firstln:~4,1%

if /i %year% GTR 0 (set month=0%firstln:~0,1%& set day=%firstln:~1,2%) else (
    set month=%firstln:~0,2%& set day=%firstln:~2,2%
)
ren %1 c01-%month%%day%.cvs
goto end

:end