Computing.Net > Forums > Disk Operating System > rename files

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

rename files

Reply to Message Icon

Name: marco76
Date: October 10, 2003 at 01:41:37 Pacific
OS: Win 2K
CPU/Ram: pentium 4/256
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: October 10, 2003 at 04:37:29 Pacific
Reply:

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 :EOF

Typing "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



0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: rename files

batch file to rename files by date. www.computing.net/answers/dos/batch-file-to-rename-files-by-date/5517.html

HELP Renaming files with a .bat file www.computing.net/answers/dos/help-renaming-files-with-a-bat-file-/3679.html

Renaming files in DOS www.computing.net/answers/dos/renaming-files-in-dos/12862.html