how to rename unknown source file names to fixed file names
Posted: 19 Mar 2016 11:42
There is a folder of files, the batch needs to change all the file names to filenameA, filenameB, filenameC ....
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
@echo off & setlocal enabledelayedexpansion
cls
set "type=.txt"
set /a Nr=100
set /a Nr+=1
pushd "%~dp0"
REM first loop
for /f "delims=" %%i in ('dir /b /a-d /on "*%type%" 2^>nul') do (
ren %%i "%%~ni-!Nr:~-2!%type%"
set /a Nr+=1
)
REM second loop
for /f "delims=" %%j in ('dir /b "*%type%" 2^>nul') do (
set str=%%~nj
set file=!str:~0,-2!
set str=!str:~-2!
set str1=!str!
for %%a in ("01=A" "02=B" "03=C" "04=D" "05=E" "06=F" "07=G" "08=H" "09=I" "10=J" "11=K" "12=L" "13=M" "14=N" "15=O" "16=P" "17=Q" "18=R" "19=S" "20=T" "21=U" "22=V" "23=W" "24=X" "25=Y" "26=Z") do (
set "str1=!str1:%%~a!"
)
set str=!str:~0,-2!!str1!
ren %%j !file!!str!!type!
)
popd
pause
Code: Select all
cmd /v:on /c "for /f %i in ('dir /b /a-d "*.txt"') do @(set "fl=%~ni" &set "fl=!fl:~0,-2!" &ren %i !fl!%~xi)"
Code: Select all
@echo off
setlocal EnableDelayedExpansion
rem Define the character set used in the new names
set "charSet=AEIOU"
set "setSize=5"
set "first="
set /A "i=0, j=0"
for /F "delims=" %%a in ('dir /B /A-D *.*') do (
rem Rename this file with new name
for %%j in (!j!) do ECHO ren "%%a" "filename!first!!charSet:~%%j,1!%%~Xa"
rem Pass to next name
set /A "j=(j+1)%%setSize"
if !j! equ 0 (
rem Increment the first char
for %%i in (!i!) do set "first=!charSet:~%%i,1!"
set /A "i=(i+1)%%setSize"
)
)