• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Any programmers here?

Arkitech

Diamond Member
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?
 
I fail to see how this is related to programming. 😕

I used to know how to do that but I'm a linux user now :Q
 
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.
 
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?
 
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.
 
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.
 
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)
 
Back
Top