How to rename files like 00080.jpg to 01080.jpg?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 174
Joined: 15 Feb 2012 14:02

How to rename files like 00080.jpg to 01080.jpg?

#1 Post by doscode » 26 Aug 2016 04:48

I need to change one digit from 0 to 1.

Also another example would help how can I change files like 99080.jpg
to 099080.jpg
(add one zero to left).
Last edited by doscode on 26 Aug 2016 08:23, edited 1 time in total.

Compo
Posts: 505
Joined: 21 Mar 2014 08:50

Re: How to rename files like 00080.jpg to 01080.jpg?

#2 Post by Compo » 26 Aug 2016 05:40

Simple use of REN [RENAME]:

Code: Select all

Ren 00080.jpg 01080.jpg
and

Code: Select all

Ren 99080.jpg 099080.jpg

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: How to rename files like 00080.jpg to 01080.jpg?

#3 Post by doscode » 26 Aug 2016 06:01

But I have hundreds of files like this.
Never mind, I found how to do it.
simply

Code: Select all

dir *.jpg /o:e /b > list.txt


I can replace it in editor.

penpen
Expert
Posts: 1859
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How to rename files like 00080.jpg to 01080.jpg?

#4 Post by penpen » 26 Aug 2016 06:41

I guess you could get a better solution if you provide more details:
We don't see what files you are working on, and we also don't know what you want to change.

Details missing:
1) Which digit do you want to change from 0 to 1:
The second digit from left, the fourth digit from right, the third zero digit from right, or how do you find the zero digit to replace?

2) What do you mean with "How to rename files like 00080.jpg to 01080.jpg?" (same for your second task)?
- 00000.jpg, 00010.jpg, 00020.jpg, 00030.jpg, ... == 000[0-9]0.jpg
- 00080.jpg, 00080.gif, 00080.png, 00080.txt, ... == 00080.<extension>
- 00000.jpg, 00001.gif, ... 00098.png, 00099.png == 000[0-9][0-9].jpg
- [0-9]0[0-9][0-9][0-9].jpg


penpen

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: How to rename files like 00080.jpg to 01080.jpg?

#5 Post by doscode » 26 Aug 2016 07:10

I have explained it:

I need to change one digit from 0 to 1. That is the change. And I said files not one file.

It is clear from the example:
00080.jpg changed to 01080.jpg

Squashman
Expert
Posts: 4194
Joined: 23 Dec 2011 13:59

Re: How to rename files like 00080.jpg to 01080.jpg?

#6 Post by Squashman » 26 Aug 2016 08:00

doscode wrote:Also another example would help how can I change files like 99080.jpg
to 099080.jpg
(add one zero to right).

Do you mean your other right (left)?

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: How to rename files like 00080.jpg to 01080.jpg?

#7 Post by doscode » 26 Aug 2016 08:22

I mean add one zero to left.

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

Re: How to rename files like 00080.jpg to 01080.jpg?

#8 Post by foxidrive » 26 Aug 2016 09:58

doscode wrote:I have explained it:

I need to change one digit from 0 to 1. That is the change. And I said files not one file.

It is clear from the example:
00080.jpg changed to 01080.jpg


It's not clear at all because you could have filename clashes during your renaming and you don't have the knowledge to realise that.

You task is explained very poorly.

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: How to rename files like 00080.jpg to 01080.jpg?

#9 Post by doscode » 26 Aug 2016 11:25

The file name is just number of video frames exported from video sequence to jpeg files. The 00000,jpg representes first frame, and some number like 000180.jpg is the last frame. So what i need to do is either to do mathematical calculation for all the frames (add a constant to variable number) 000150(.jpg)+001000(.jpg) = "001150.jpg" or just to change one digit. Because the number.

penpen
Expert
Posts: 1859
Joined: 23 Jun 2013 06:15
Location: Germany

Re: How to rename files like 00080.jpg to 01080.jpg?

#10 Post by penpen » 26 Aug 2016 14:16

This might help you (?for both tasks?; untested - actually i have few time):

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion
:: unsorted list
set "list=list.txt"
:: sorted list
set "slist=slist.txt"
:: constant to add
set "const=1000"

:: assumed there are a maximum of 6 digits in the name
set "prefix=000000"
set "pLength=6"

:: %list% will contain: "<normalized filename>"?"<original filename>"
> "%list%" (
for /F tokens^=1^-2^ delims^=^.^" %%a in ('dir *.jpg /b') do (
   set "filename=%%~a"
   set "filename=!prefix!!filename!"
   set /A "filename=1!filename:~-%pLength%!+const-1!prefix!"
   set "filename=!prefix!!filename!"
   set "filename=!filename:~-%pLength%!"

   echo("!filename!.%%~b"?"%%~a.%%~b"
)
)

:: ensure nothing is overwritten when renaming: sort reverse (== rename biggest numbers first)
sort /r "%list%" /o "%slist%"

:: rename
for /F "usebackq tokens=1-2 delims=?" %%a in ("%slist%") do (
   ren "%%~b" "%%~a"
)
endlocal


penpen

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: How to rename files like 00080.jpg to 01080.jpg?

#11 Post by doscode » 27 Aug 2016 09:09

Thanks. I think CMD is too much complicated for this kind of job. This is quite not easy. It is better to choose different language which is able to do it with very simple commands than using CMD.

Using CMD, the fastest solution is what I suggested: to list the files and send it to bat file, which I can edit using notepad string replace.... This way it is very easy.

Sponge Belly
Posts: 200
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: How to rename files like 00080.jpg to 01080.jpg?

#12 Post by Sponge Belly » 28 Aug 2016 03:03

Hi Doscode! :)

Maybe Dave Benham’s JREN.BAT can do what you want. Requires some knowledge of JavaScript regular expressions.

HTH!

- SB

Post Reply