renaming files

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Jun 15, 2008
5
0
#1
I must rename a big number of files. The old name is
xxxxxx_0001.jpg,
xxxxxx_0001.jpg,
xxxxxx_0001.jpg
......

the new name should be
00001.jpg
00002.jpg
.....
00010.jpg
.....

I am not so familar with takecommand, so I need help
Thanks in advance
Karl
 
Jun 11, 2008
26
0
#2
gunkelkarl wrote:

> I must rename a big number of files. The old name is
> xxxxxx_0001.jpg,
> xxxxxx_0001.jpg,
> xxxxxx_0001.jpg
> ......
Do you really have identical existing filenames as illustrated above?



>
> the new name should be
> 00001.jpg
> 00002.jpg
> .....
> 00010.jpg
> .....
>
> I am not so familar with takecommand, so I need help
> Thanks in advance
> Karl
Karl

You really need to provide more info on what you have and the result you
want and in this case what is the relationship between the source name
and the target name.

--
Regards
John McMahon
lists@jspect.fastmail.fm

http://catb.org/~esr/faqs/smart-questions.html
 
Jun 3, 2008
27
0
#3
On Mon, 16 Jun 2008 05:35:37 -0500, jmcm <> wrote
Re RE: [Support-t-199] renaming files:


>gunkelkarl wrote:
>
>
>---Quote---
>> I must rename a big number of files. The old name is
>> xxxxxx_0001.jpg,
>> xxxxxx_0001.jpg,
>> xxxxxx_0001.jpg
>> ......
>---End Quote---
>Do you really have identical existing filenames as illustrated above?
>
>
>
>
>---Quote---
>>
>> the new name should be
>> 00001.jpg
>> 00002.jpg
>> .....
>> 00010.jpg
>> .....
>>
>> I am not so familar with takecommand, so I need help
>> Thanks in advance
>> Karl
>---End Quote---
>Karl
>
>You really need to provide more info on what you have and the result you
>want and in this case what is the relationship between the source name
>and the target name.
Or, if you have to do this kind of renaming often, you can just try
the freeware ReName Master.

http://www.joejoesoft.com/cms/showpage.php?cid=108

I use it often. It's very good.
--
At first they laugh at you, then they ignore you, then they fight you, then you win.
 
#5
gunkelkarl wrote:


Do you really have identical existing filenames as illustrated above?

>> xxxxxx_0001.jpg,
>> xxxxxx_0002.jpg,
>> xxxxxx_0003.jpg


sorry - I was sleeping on one eye :-)

QuickNDirty.BTM

dir /b *.jpg >input.dat

do r=0 to %@lines[input.dat]
set fifo=%@line[input.dat,%r]
ren /N %fifo %@instr[%@inc[%@index[%fifo,_]],,%fifo]
enddo

From what I could gather from your original post you want the above.

"NOTE" /N(othing) after "ren"ame remove "/n" when you are sure this is what you want it to do.
 
#6
gunkelkarl wrote:
|
gunkelkarl wrote:
|
|
| Do you really have identical existing filenames as illustrated above?
|
||| xxxxxx_0001.jpg,
||| xxxxxx_0002.jpg,
||| xxxxxx_0003.jpg

If the last 4 characters of the file's name already represent the desired
new name, and the files are to remain in their current directory, the
UNTESTED method below should work:

do x in *_[0-9][0-9][0-9][0-9].jpg
ren %x 0%@right[8,%x]
enddo

If the task is more complicated, e.g., the last four numbers of the original
names cannot be relied upon to be unique, you may want to do something more
elaborate:

set base=100000
do x in *_*.jpg
set n=%@right[5,%base].jpg
ren %x %n
set base=%@inc[%base]
enddo

Hope this gives you some ideas howto do the job.
--
Steve
 
#7
Rex Clark wrote:
|
| QuickNDirty.BTM
|
| dir /b *.jpg >input.dat
|
| do r=0 to %@lines[input.dat]
| set fifo=%@line[input.dat,%r]
| ren /N %fifo %@instr[%@inc[%@index[%fifo,_]],,%fifo]
| enddo

Your method is very slow because of the manner @LINES works. Furthermore,
splitting the name via @INSTR[] after locating the proper location using
@INDEX is superfluous according to the file name formats in the modified OP.

An equivalent method, without the need for the auxiliary file, is in my
response to the OP.

|
| "NOTE" /N(othing) after "ren"ame remove "/n" when you are sure this
| is what you want it to do.

An excellent point. I usually put the /n at the tail end of the command
(esp. interactively) for easier removal.
--
Steve
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#10
I was going to suggest using the newer syntax of regular expressions and
delayed expansion to accomplish the task in a single rename statement but
I think I've uncovered a glitch.

I created 10 files:
for /l %c in (1,1,10) do echo. >file_%@format[04,%c].jpg

Then I created an 11th special case:
echo. >file_0011a.jpg

Then I tried to rename it using this syntax:
ren /n "::.*_\d\d\d\d\.jpg" %%@right[8,*]

Which in theory should rename the files (with the exception of the 11th)
to the last 4 digits and the extension.

@name appears to work but @right is failing miserably.

-Scott

Steve F$BaC(Bi$BaO(B <> wrote on 06/16/2008 09:16:06 AM:


> gunkelkarl wrote:
> |
gunkelkarl wrote:
> |
> |
> | Do you really have identical existing filenames as illustrated above?
> |
> ||| xxxxxx_0001.jpg,
> ||| xxxxxx_0002.jpg,
> ||| xxxxxx_0003.jpg
>
> If the last 4 characters of the file's name already represent the
desired

> new name, and the files are to remain in their current directory, the
> UNTESTED method below should work:
>
> do x in *_[0-9][0-9][0-9][0-9].jpg
> ren %x 0%@right[8,%x]
> enddo
>
> If the task is more complicated, e.g., the last four numbers of the
original

> names cannot be relied upon to be unique, you may want to do something
more

> elaborate:
>
> set base=100000
> do x in *_*.jpg
> set n=%@right[5,%base].jpg
> ren %x %n
> set base=%@inc[%base]
> enddo
>
> Hope this gives you some ideas howto do the job.
> --
> Steve
>
>
 
#11
samintz wrote:
| I was going to suggest using the newer syntax of regular expressions
| and delayed expansion to accomplish the task in a single rename
| statement but
| I think I've uncovered a glitch.
|
| I created 10 files:
| for /l %c in (1,1,10) do echo. >file_%@format[04,%c].jpg

Two independent simplifications.
1/ Use touch/c to create empty files.
2/ Use for/l %c in (10001,1,10010) in the loop, and use %@right[4,%c] in the
file name. This is simpler in some contexts, though in the present context
may not actually be faster or easier to understand. BTW, I have UDFs for
fz2=`%@format[02,%1]` through fz9 to simplify the task using your control
variable.
|
| Then I created an 11th special case:
| echo. >file_0011a.jpg
|
| Then I tried to rename it using this syntax:
| ren /n "::.*_\d\d\d\d\.jpg" %%@right[8,*]
|
| Which in theory should rename the files (with the exception of the
| 11th)
| to the last 4 digits and the extension.
|
| @name appears to work but @right is failing miserably.

Using TCC 9.02.151 Windows XP [Version 5.1.2600] (in its own window) I
found the same issue with the command

ren *_[0-9][0-9][0-9][0-9].jpg %%@right[8,*]

the target names were identical to the source names. However, puuting
quotation marks around the target name thus:

ren *_[0-9][0-9][0-9][0-9].jpg "%%@right[8,*]"

worked like a charm. It properly renamed files 1..10, and left alone the
"1a" file.
--
Steve
 

rconn

Administrator
Staff member
May 14, 2008
10,162
86
#12
samintz wrote:

> I was going to suggest using the newer syntax of regular expressions and
> delayed expansion to accomplish the task in a single rename statement but
> I think I've uncovered a glitch.
>
> I created 10 files:
> for /l %c in (1,1,10) do echo. >file_%@format[04,%c].jpg
>
> Then I created an 11th special case:
> echo. >file_0011a.jpg
>
> Then I tried to rename it using this syntax:
> ren /n "::.*_\d\d\d\d\.jpg" %%@right[8,*]
>
> Which in theory should rename the files (with the exception of the 11th)
> to the last 4 digits and the extension.
>
> @name appears to work but @right is failing miserably.
Nothing to do with @RIGHT; the problem is because you've failed to quote
the target. The ',' inside @RIGHT is being interpreted as an argument
separator (whitespace), so REN thinks the target filename is supposed to
be "*]". I tried it here with the quotes in place and it worked as
expected.

Rex Conn
JP Software
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#13
Cool beans!

So an actual syntax that works is:
ren "::.*_\d+\.jpg" "%%@right[8,*]"

The RegEx says: zero or more of any character (.*) followed by underscore
(_) followed by 1 or more numeric digits (\d+) followed by .JPG (\.jpg).
Delayed expansion can then be used to manipulate the name anyway you want.

However, I tried to get a more generic solution for a file that starts
with arbitrary characters, an underscore, followed by an arbitrary number
of digits, then .jpg. The @right works above because the filenames all
have 4 digits at the end of their names. So I tried to use @REGEXSUB.

ren /n "::.*_\d+\.jpg" "%%@regexsub[1,(\d+)$,%%@name[*]].jpg"

This works:
echo %@regexsub[1,(\d+)$,%@name[file_0001.jpg]]
0001

But the REN statement does not. What's wrong with my syntax?
-Scott

rconn <> wrote on 06/16/2008 02:58:55 PM:


> samintz wrote:

> Quote:
>
> > I was going to suggest using the newer syntax of regular expressions
and

> > delayed expansion to accomplish the task in a single rename statement
but

> > I think I've uncovered a glitch.
> >
> > I created 10 files:
> > for /l %c in (1,1,10) do echo. >file_%@format[04,%c].jpg
> >
> > Then I created an 11th special case:
> > echo. >file_0011a.jpg
> >
> > Then I tried to rename it using this syntax:
> > ren /n "::.*_\d\d\d\d\.jpg" %%@right[8,*]
> >
> > Which in theory should rename the files (with the exception of the
11th)

> > to the last 4 digits and the extension.
> >
> > @name appears to work but @right is failing miserably.
>
> Nothing to do with @RIGHT; the problem is because you've failed to quote

> the target. The ',' inside @RIGHT is being interpreted as an argument
> separator (whitespace), so REN thinks the target filename is supposed to

> be "*]". I tried it here with the quotes in place and it worked as
> expected.
>
> Rex Conn
> JP Software
>
>
 
#14
Rex Clark wrote:
|
| QuickNDirty.BTM
|
| dir /b *.jpg >input.dat
|
| do r=0 to %@lines[input.dat]
| set fifo=%@line[input.dat,%r]
| ren /N %fifo %@instr[%@inc[%@index[%fifo,_]],,%fifo]
| enddo

Your method is very slow because of the manner @LINES works. Furthermore,
splitting the name via @INSTR[] after locating the proper location using
@INDEX is superfluous according to the file name formats in the modified OP.


An equivalent method, without the need for the auxiliary file, is in my
response to the OP.

|
| "NOTE" /N(othing) after "ren"ame remove "/n" when you are sure this
| is what you want it to do.

An excellent point. I usually put the /n at the tail end of the command
(esp. interactively) for easier removal.
--
Steve
Why would %@lines matter it only needs to know how many lines to read in the file .. it s only done once. so theres 2343 lines it takes less than 2 seconds to get what it needs to continue.

as for %@line[] its got its filename "%r" profides the next line number

I could of used fileread/open/seek
To much syntax for a simple job when the above does what its told ... given the translation i got from his original post in regards to his file re-naming criteria. it was "QuickNDirty" no testing of complex regexp

regular expressions would of work too

I find having code/scripting whatever easier todo if the code itself was more descriptive than writting "comments under or above the syntax to explain what it does". I hate comments they are sometimes more confusing than the actual code. But thats just me.
 
#15
I must respond with a Sorry to All..
I re-read his original post and found that the file naming criteria he
requested
would not work in this QuickNDirty.BTM

a) xxxxxx_0001.jpg, xxxxxx_0001.jpg,xxxxxx_0001.jpg
all the same endpoints 0001.jpg

QuickNDirty was expecting _0001.jpg _0002.jpg etc.. in auxiliary file
"input.dat"

Sorry Steve .. and anyone else who thought I was an idiot.

----- Original Message -----
From: "Rex Clark" <>
To: <rexxc@slingshot.co.nz>
Sent: Tuesday, June 17, 2008 2:47 PM
Subject: RE: [Support-t-199] Re: renaming files


: ---Quote (Originally by Steve Fábián)---
: Rex Clark wrote:
: |
: | QuickNDirty.BTM
: |
: | dir /b *.jpg >input.dat
: |
: | do r=0 to %@lines[input.dat]
: | set fifo=%@line[input.dat,%r]
: | ren /N %fifo %@instr[%@inc[%@index[%fifo,_]],,%fifo]
: | enddo
:
: Your method is very slow because of the manner @LINES works. Furthermore,
: splitting the name via @INSTR[] after locating the proper location using
: @INDEX is superfluous according to the file name formats in the modified
OP.
:
:
: An equivalent method, without the need for the auxiliary file, is in my
: response to the OP.
:
: |
: | "NOTE" /N(othing) after "ren"ame remove "/n" when you are sure this
: | is what you want it to do.
:
: An excellent point. I usually put the /n at the tail end of the command
: (esp. interactively) for easier removal.
: --
: Steve
: ---End Quote---
: Why would %@lines matter it only needs to know how many lines to read in
the file .. it s only done once. so theres 2343 lines it takes less than 2
seconds to get what it needs to continue.
:
: as for %@line[] its got its filename "%r" profides the next line number
:
: I could of used fileread/open/seek
: To much syntax for a simple job when the above does what its told ...
given the translation i got from his original post in regards to his file
re-naming criteria. it was "QuickNDirty" no testing of complex regexp
:
: regular expressions would of work too
:
: I find having code/scripting whatever easier todo if the code itself was
more descriptive than writting "comments under or above the syntax to
explain what it does". I hate comments they are sometimes more confusing
than the actual code. But thats just me.
:
:
:
:
: