Batch rename
Results 1 to 3 of 3

Thread: Batch rename

  1. #1
    Join Date
    Jan 2002
    Location
    Misssissauga, ON, Canada
    Posts
    5

    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.

  2. #2
    Join Date
    Sep 2000
    Posts
    937
    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

  3. #3
    Join Date
    Feb 2000
    Location
    Idaho Falls, Idaho, USA
    Posts
    18,428

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •