• The Forums are now open to new registrations, adverts are also being de-tuned.

Batch File Renaming

Spinal

MB Enthusiast
Joined
Sep 14, 2004
Messages
4,806
Location
between Uxbridge and the Alps
Car
x254, G350, Duster, S320, Mach1, 900ss and a few more
I need to rename a set of files on a windows box... the current format is:
file name [2009].ext

and I need to replace it with:
file name (2009).ext

so a fairly simple change... In *nix I can just create a bash script with a little loop to do it for me, but I don't know how to do this in Windows...

Does anyone know of a Windows program that will do this? I really don't want to transfer everything to an external HD just to rename them :p

Thanks!

M
 
the command you want is included in the windows shell. From the prompt type: for /? and check out the syntax.

I've spent the last 5 mins trying to work out how to rename your files but it's slightly beyond me. Right now I have this in a batch file: for %%a in (*[2009].*) do ren %%a *(2009).*

The result is echo'd:
C:\>ren file name 1 [2009].ext *(2009).*
The syntax of the command is incorrect.

It's so close! Perhaps after a coffee it will become clear :)
 
if <file name> is a fixed number of chars you can do

ren ????????[2009].ext ????????(2009).ext

* doesn't work though

perhaps just repeat a few times with different numbers of ??s
 
One thing I have done in the past for one off operations like this is to pipe a directory listing to a file, load in excel (fixed width delimiters as required) then used a few excel formula to generate the commands as rows in excel then write back out to a batch file.
 
I don't actually run Windows, but the suggestion that you need to export the list of file names to a spreadsheet to be able to manipulate them made my blood boil so I had to respond ;-)

First of all, if you do have to use Windows, I strongly recommend installing a unix-like environment precisely for this kind of reason. Cygwin (sourceware.org: Free software! Get your fresh hot free software!) is the most well known, although there are many others out there.

For this specific issue, you could use Multi File Renamer | Get Multi File Renamer at SourceForge.net (an older project and no longer being maintained, but it works just fine). You could probably also do what you need using Total Commander (Total Commander - home) as a multi-stage set of renames.

Or of course you could use the ren command:

ren *[2009].ext *(2009).ext

(This appears to work on the Windows VM I just started, but my sample list of file names might not match yours).

-simon
 
Or of course you could use the ren command:

ren *[2009].ext *(2009).ext

(This appears to work on the Windows VM I just started, but my sample list of file names might not match yours).
I don't know why I wandered off into that for loop when the wildcard statement inside it would have worked on it's own! :doh:
 
I don't know why I wandered off into that for loop when the wildcard statement inside it would have worked on it's own! :doh:

Maybe because you though that the date is variable ;) (which it is, the files range from the late 70's to nowadays)...

That worked a charm - thanks ;) I ended up just running the ren command a few times (once per "year")

I still prefer nix environments :p I'm sure windows has something similar built in - but I'm just not that familiar with it at this level (as much as I adore windows I'm just a user in Windows)

Thanks - you've made my XBMC a MUCH happier bunny ;) How do I append the [solved] to the thread title - or are we not doing that anymore?

M.
 
I don't actually run Windows, but the suggestion that you need to export the list of file names to a spreadsheet to be able to manipulate them made my blood boil so I had to respond ;-)

You're not alone:rolleyes:
 
I don't actually run Windows, but the suggestion that you need to export the list of file names to a spreadsheet to be able to manipulate them made my blood boil so I had to respond ;-)
I would say I've never used for renaming, usually used for more complex operations and in customer environments where I can't just download any tool I want.

ren *[2009].ext *(2009).ext
(This appears to work on the Windows VM I just started, but my sample list of file names might not match yours).
My first thought - but it only worked when the * was at the end of the <filename> not at the start (I had just got out of bed). Just tried again and it must have been the example I tried as it sometimes fails

e.g.

[cc]0090308_191031.reg

ren *031.reg *131.reg

produces

[cc]0090308_19103131.reg

not

[cc]0090308_191131.reg

:confused:

I'm sure I remember having an issue with * wildcards in renames many, many years ago (i.e in DOS3.1), but can't remember what it was.
 
I'm sure I remember having an issue with * wildcards in renames many, many years ago (i.e in DOS3.1), but can't remember what it was.
The issue is that * describes any number of characters and ? covers just one character. The tools are mostly there in the shell it's just getting the various rules and switches sorted out. I used to get tons of stuff done with batch files but stopped a LONG time ago (basically when windows 3 appeared).

It is nice to see that nearly all of the tools still exist in XP etc and that they have been upgraded/tweaked over the years dispite their popularity surely dipping!
 
More than just that - renaming using * is just plain buggy - try creating fred.log and then doing ren *ed.log *rd.log, result is not what you expect - try again with ?? and all is as expected.

With * it's like it recurses (fred -> frrd -> frd) - that rings bells actually.
 
There's a nice OS X application called "A better Finder rename" which does this kind of thing very well and has a decent interface

Nick Froome
 
I use a freeware application called "Batch File Renamer". It does what it says on the tin, has an easy to use interface and can handle variables with aplomb.
 

Users who are viewing this thread

Back
Top Bottom