-
Batch rename
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.
-
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
-