Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have to rename a set of file with name like this:
CR.1.3.46.670589.26.300060.4.20030929.171535.817.0
or
CR.1.3.46.670589.26.300060.4.20030929.172025.818.0
in files with name like 817 and 818 and so on.
So, I have to delete the first 45 characters and the extension .0 .
I read the program below in this forum:@echo off
if "%1"=="GoTo" goto %2
if not "%OS%"=="Windows_NT" goto eof
%comspec% /v:on /c %0 GoTo start
goto eof:start
echo.
echo This program will rename all files from the current directory,
echo and possibly from its subdirectories, following a certain rule.
echo.
echo Press any key to VIEW the renaming process . . .
pause > nul
echo Processing . . .type nul> %temp%.\process.bat
:: To include the files under subdirectories from current
:: directory on the renaming process, add the string ' /R'
:: after the string 'for' on the next line, so it becomes
:: 'for /R' (don't forget the space between the strings)
for %%F in (*.*) do (
set ORIG=%%~nF
set ORIG=!ORIG:-=!
set FILE=!ORIG:~3,-4!
set EXT=!ORIG:~-4,-1!
if not "!FILE!"=="" if not "!EXT!"=="" (
echo REN "%%F" "!FILE!.!EXT!">> %temp%.\process.bat
)
)echo.
type %temp%.\process.bat |MORE
echo The above process is NOT reversible.
echo.
set CH=
:loop
set /P CH=To you wish to execute the above process [Y/N]?
if /i "%CH%"=="Y" (
call %temp%.\process.bat
echo.
echo Operation done.
del %temp%.\process.bat
goto eof
)
if /i "%CH%"=="N" (
echo.
echo Operation aborted
del %temp%.\process.bat
goto eof
)
goto loop:eof
Could I modify this program and if yes, how could I modify it to obtain what I need?
Thank you very much

If you have to rename files as those you posted, .0 extension and fixed format filename, it is more practical you try the following:
@Echo Off
For /F "tokens=*" %%I in ('Dir /B %~f1.\*.0') Do Call :REN %~f1 %%I
GoTo :EOF:REN
Set FName=%~n2
Echo Ren %~f1.\%2 %FName:~45%
GoTo :EOFTyping "MyRen Folder" (where MyRen is the name of the batch and Folder the directory storing the files .0) you accomplish your job.
When sure the script works as you planned, activate it by removing the Echo in front of the Ren command.
Good Work

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |