Re: Reverse numerotation of files !

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Jeremy" wrote in message
> Hello,
>
> I have many files in one folder. Here is one exemple of file name :
> pics - 05/02/2005 001.jpg
> ...
> pics - 05/02/2005 300.jpg
>
> I wish I could reverse the numerotation of the files :
> pics - 05/02/2005 001.jpg will become pics - 05/02/2005 300.jpg
> ...
> pics - 05/02/2005 300.jpg will become pics - 05/02/2005 001.jpg
>
> Is it possible ?
> I don't really know how to script but I really need to do that!!
> Could somebody help me please ?

This demo assumes that all the files match the wildcard pics*.jpg
(where * means any number of characters). It also assumes that
the final numbering characters match a three digit range 001-999.

It should prompt you for the start number (in your example = 1)
and the finish number (in your example=300) and then rename
each file to (Start+Stop)-(file's current number) with lead zeros for
numbers less than 100. So in your example, 001 becomes 300,
300 becomes 001 and so on.

Note that the demo does an intermediate REName to *.JP_
(assumes you have no files with extension .JP_ at present), to
avoid clashing with existing files during the process. At the end
of the run all the *.JP_ files are RENamed back to *.JPG extension.

Try it out on a few copied example files first to see if it does what
you want.

Lines that don't begin with two spaces have wrapped accidentally
====Begin cut-and-paste (omit this line)
@ECHO OFF
SETLOCAL
SET /p START="Enter start of file numbering "
SET /p STOP="Enter end of file numbering "
SET /a TOGGLE=%START%+%STOP%
:: Assumes files match pics*.jpg
FOR %%F IN (pics*.jpg) DO CALL :_RENAME "%%F"
ECHO. Renaming all *.JP_ to *.JPG
REN *.JP_ *.JPG
GOTO :EOF

:_RENAME
SET BN=%~n1
SET FirstPart=%BN:~0,-3%
SET LastThree=%BN:~-3%
SET /a LastThree=1000+%TOGGLE%-%LastThree%
SET LastThree=%LastThree:~-3%
ECHO. Renaming %1 to "%FirstPart%%LastThree%.JP_"
REN %1 "%FirstPart%%LastThree%.JP_"

====End cut-and-paste (omit this line)
Simulated Win2000 for study/demo use. Cut-and-paste as Batch text file.
Batch file troubleshooting: http://www.allenware.com/find?UsualSuspects

--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
Header email is rarely checked. Contact us at http://www.allenware.com/


.



Relevant Pages

  • Re: Multi change batch file
    ... I want to write a simple DOS batch file to rename the ... files in a list of 65 .jpgs, ... @echo off ...
    (comp.os.msdos.programmer)
  • Re: Reverse numerotation of files !
    ... @ECHO OFF ... Renaming all *.JP_ to *.JPG ... Cut-and-paste as Batch text file. ... to the SET /p input prompts). ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Random file naming in cmd
    ... @echo off & setlocal ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION ... After testing remove the echo line and uncomment the ren (rename) line ... >do this but don't know if batch supports the. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Batch File to manipulate path and file name
    ... It should process any "poison" characters ... # echo Full name=%%a ... If you object to requiring two files to achieve your aim (one batch, ... How do I get from Input File Name to Output File Name Desired? ...
    (microsoft.public.windowsxp.general)