Re: Command Line Question about Renaming Files

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Pegasus \(MVP\) (I.can_at_fly.com)
Date: 03/24/04


Date: Wed, 24 Mar 2004 17:23:20 +1100


"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:u7LLgeWEEHA.2404@TK2MSFTNGP11.phx.gbl...
>
> "Mark & Mary Ann Weiss" <mweissX294@earthlink.net> wrote in message
> news:Hn98c.5139$HP.4959@newsread2.news.atl.earthlink.net...
> > I have a large number of files that begin with "01-", 02-", and so on.
The
> > filenames are varying lengths, but the extension is always 3 characters.
> >
> > Using the Windows 2000 command line, is it possible to batch rename
these
> > files such that the first three characters are stripped from the
filename?
> > If so, can someone post an example?
> >
> > --
> > Take care,
> >
> > Mark & Mary Ann Weiss
> >
> > VIDEO PRODUCTION . FILM SCANNING . AUDIO RESTORATION
> > Hear my Kurzweil Creations at: http://www.dv-clips.com/theater.htm
> > Business sites at:
> > www.dv-clips.com
> > www.mwcomms.com
> > www.adventuresinanimemusic.com
> > -
>
> Try this batch file. Note that it won't to its job properly
> if you end up with ambiguous names. For example, if
> you have these two files
>
> HisMusic.rm
> HerMusic.rm
>
> then there will be an obvious clash.
>
> @echo off
> if exist %temp%\NewName.bat del %temp%\NewName.bat
>
> for %%* in (*.*) do call :Strip %%*
> call %temp%\NewName.bat
> del %temp%\NewName.bat
> goto :eof
>
> :Strip
> set name=%*
> set NewName=%name:~3%
> echo ren "%Name%" "%NewName%" >> %temp%\newname.bat
>
>

To avoid unpleasant surprises because of unexpected behaviour,
you should probably run this version of the batch file first. It only
pretends to go through the motions but it won't rename any files.

@echo off
if exist %temp%\NewName.bat del %temp%\NewName.bat

for %%* in (*.*) do call :Strip %%*
echo Examine %temp%\NewName.bat to see what will happen,
echo then execute %temp%\NewName.bat.

rem call %temp%\NewName.bat
rem del %temp%\NewName.bat
goto :eof

:Strip
set name=%*
set NewName=%name:~3%
echo ren "%Name%" "%NewName%" >> %temp%\newname.bat



Relevant Pages

  • Re: Scheduled Task error code:The task completed with an exit code
    ... echo %fileDATE%>filedate.txt ... if exist concatdate.txt del /q concatdate.txt ... You consistently fail to specify a drive and a path for your ... *** You must specify the exact file locations. ...
    (microsoft.public.windows.server.general)
  • Re: cc65 and "Hello World"
    ... There is a section in the Aztec C ReadMe about starting Aztec C SYS ... Many ProDOS system programs created using Aztec C65 will crash ... del time.r ... @echo cinit.ovr now created! ...
    (comp.sys.apple2.programmer)
  • Re: find and remove duplicate files
    ... > What are those strings of characters? ... echo commands. ... wit a "del " ...
    (microsoft.public.win2000.cmdprompt.admin)
  • RE: comments
    ... operating system. ... @echo off ... echo COUNTRY: DENMARK>>info.txt ... del ncurses.tar.gz ...
    (freebsd-questions)
  • Re: Batch file for cleaning up
    ... Cleaning the TIF folders using del and all files will only create ... Delete/Empty Temporary Internet Cache completely ... > echo * CCC L OOO SSS EEE * ...
    (microsoft.public.windows.inetexplorer.ie6.browser)