Any programmers here?

Arkitech

Diamond Member
Apr 13, 2000
8,356
4
76
This is probably a simple question for the programming gurus


I'm trying to rename large groups of files using a dos batch command but for some reason its not working.

For example lets say there are 20 files named "data file #1.txt", "data file #2.txt", etc... but I want to rename them to "data file - 2004 - #1.txt". How would I write the command for that?


Here's what I tried to do before "ren data file #*.* data file - 2004 - #*.*" , but for whatever reason it did'nt work. Anyone have some suggestions on how to accomplish this?
 

MAME

Banned
Sep 19, 2003
9,281
1
0
I fail to see how this is related to programming. :confused:

I used to know how to do that but I'm a linux user now :Q
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
for my $ii(1..20){
`ren "data file #$ii.txt" "data file - 2004 - #$ii.txt"`;
}

Yeah, my windows machines all have perl interpreters on them.
 

MAME

Banned
Sep 19, 2003
9,281
1
0
Originally posted by: notfred
for my $ii(1..20){
`ren "data file #$ii.txt" "data file - 2004 - #$ii.txt"`;
}

Yeah, my windows machines all have perl interpreters on them.

I have to write a tutorial for Perl and all I know is how to spell "perl" and that it has a camel mascot. Could you perhaps lend tell me what are good things to present for a tutorial? Perhaps things that are unique to the language?
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Originally posted by: Arkitech
This is probably a simple question for the programming gurus


I'm trying to rename large groups of files using a dos batch command but for some reason its not working.

For example lets say there are 20 files named "data file #1.txt", "data file #2.txt", etc... but I want to rename them to "data file - 2004 - #1.txt". How would I write the command for that?


Here's what I tried to do before "ren data file #*.* data file - 2004 - #*.*" , but for whatever reason it did'nt work. Anyone have some suggestions on how to accomplish this?

Put each file name in quotes.
ren "data file #*.*" "data file - 2004 - #*.*"

That might work, although you may need to use a for command to look up the name of each file individually. I'm not sure if you can do a batch rename like this.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
Originally posted by: MAME
Originally posted by: notfred
for my $ii(1..20){
`ren "data file #$ii.txt" "data file - 2004 - #$ii.txt"`;
}

Yeah, my windows machines all have perl interpreters on them.

I have to write a tutorial for Perl and all I know is how to spell "perl" and that it has a camel mascot. Could you perhaps lend tell me what are good things to present for a tutorial? Perhaps things that are unique to the language?

It's good with regular expressions.

$filename =~ s/(data file) (#\d+)/$1 - 2004 - $2/;

Really, it does certain things well. I can't really teach it to you well enough that you can teach it to other people in just a paragraph or two.
 

darktubbly

Senior member
Aug 19, 2002
595
0
0
Try this:

for /F "usebackq tokens=1,2 delims=#" %f in (`dir *.txt /b`) do ren "%f#%g" "%f- 2004 - #%g"

(Be sure to make a copy of the original files before you run this though)