Click to See Complete Forum and Search --> : Batch rename


Domcio
January 11th, 2002, 10:43 AM
Hello there,
I have this directory full of "camera xxxx.htm" files. I need to rename them to be just xxxx.htm. There must be a simple way of doing it under cmd prompt. I have tried rename "camera *.htm" *.htm but of course it did not work. Anyone has any ideas? Using move could work as well. I just want to get rid of the lond file format so I can process those files in SQL server. For some reason SQL server does not like dealing with the long file names.

Wavey Davey
January 11th, 2002, 11:32 AM
One way (test before using)...

rem rtest.bat
@echo off
setlocal
rem Split name and extension
for %%i in (*.*) do (
set name=%%~ni
set ext=%%~xi
call :RenFile
)

:RenFile
endlocal
rem Remove first 7 characters of name
set name-7="%name:~7%"

rem If filename is 7 characters or less skip rename
if %name-7%=="" goto :ERROR

rem If proposed new filename already exists skip the rename
if exist %name-7%"%ext%" goto :ERROR

rem Rename original
ren "%name%%ext%" %name-7%"%ext%"

:ERROR

jdc2000
January 11th, 2002, 12:23 PM
Download multiren here:
http://www.pcmag.com/article/0,2997,a%253D9926,00.asp