renaming files

Jun 15, 2008
5
0
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
29
0
Australia
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
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.
 
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.
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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,511
18
Solon, OH, USA
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
>
>
 
May 20, 2008
3,515
4
Elkridge, MD, USA
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
12,404
152
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,511
18
Solon, OH, USA
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
>
>
 
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.
 
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.
:
:
:
:
:
 
Similar threads
Thread starter Title Forum Replies Date
M Another problem with renaming files... Support 3
P Renaming files with regex. Support 6
JohnQSmith Regex renaming Support 2
P Renaming with a RegEx Support 1
J Extended directory search - cure by renaming tcmd.ini Support 10
nickles Renaming bug? Support 9
S GPF after successfully renaming directories on an ftp server Support 2
M More file-renaming problems involving commas... Support 0
MickeyF TCC crashing when copying multiple files (now resolved) Support 6
fpefpe How to? shortcuts and batch files Support 4
C v28 key files Support 2
J ffind does not find files Support 4
C duplicate files in multiple plugin sites Support 9
Dmitry L. Kobyakov Fixed The SETARRAY /R command works incorrectly with cyrillic files Support 2
S How to? Deinstalling TC/reinstating execution of bat files by cmd in Win7 Support 31
vefatica FFIND, temp files? ... not deleted? Support 0
R FUNCTION to count NUMBER of files matching a pattern and specific length/not length Support 4
vefatica Tmp files from in-process pipes not deleted Support 6
vefatica Finding files with alternate data streams? Support 4
rps Multi-column DIR /v not displaying all files. Support 5
D How to skip files in a fileset? Support 6
vefatica PIPEVIEW leaves TMP files Support 18
K "copy /z /w" command not deleting read-only files in destination Support 10
Jesse Heines "Taken" date for JPG and PNG files Support 4
O I cannot use links to .btm files Support 5
C How to? rename files with spaces Support 8
R How to? Append files in multiple subfolders using copy? Support 8
Joe Caverly "Functions" in cmd.exe batch files Support 6
S Batch files Calling Batch Files Support 2
vefatica Find Files/Text dialog: does it work? Support 0
Joe Caverly UNZIPping older .ZIP files Support 3
C Documentation default location for LOG files Support 21
P exit /b in batch files Support 7
P Labels in batch files: TCC vs CMD.exe Support 9
M ANSI is used to show files instead of OEM in version 17 to 19 ! Support 5
C 7Z files on forum? Support 0
x13 Problem listing repository files using DIR http(s)://... Support 8
B Can copy command concatenate multiple mp3 files Support 2
redwdc Copying files with spaces, commas, etc. Support 5
J New lexer for TCC batch files. Support 0
M How to? want to download a file from a website enumarate the links and download the files Support 2
keithg1964 TCC RT Install Files Support 1
P Fixed Rexx .cmd files no longer work in TCC 20 Support 3
thorntonpg Handling files with embedded spaces Support 1
WavSlave Fixed Unable to sort files by description in TCC v19 Support 2
P Files older - exist Support 1
D safe delete files command Support 10
P Copying files in subdirectories Support 9
C WAD VIEW print multiple files - switches fail Support 10
MikeBaas How to? SELECT: exclude files / display prompt Support 2

Similar threads