Looking for batch file renamer

Started by Gregjazz, Sun 03/05/2009 01:56:32

Previous topic - Next topic

Gregjazz

People on this forum have been so helpful to me in the past, I thought I'd try my luck yet again.

I'm looking for a batch file renamer which will rename files based on rules. For example:

If the file contains a "D2" in the file name, add "01" to the beginning of the file name.
If the file contains a "D#2" in the file name, add "02" to the beginning of the file name.

The interface might not be set up this way, but as long as it can do this task, that's all I ask for.

And so forth. I found the software "Sophisticated Rename" which allows me to do this. However, I don't want to pay $60 in case there is other software out there that does this.

Leon

I use the BulkRenameUtility.
It's free, easy to use and has endless posibilities. You can even do some basic scripting with it for repeated actions or sequenced renaming (first remove ... then with the remainder add ... etc.)
Ultimate Game Solutions - Because there is a solution for everything

AGA

I use AF5. It has a few more sophisticated functions that I never bothered working out how to use, so it might work.

Gregjazz

#3
I tried both, but I still can't do what I want.

For example, BulkRenameUtility--there's only one match/replace box. I need 30 separate matches/replaces for different strings.

Well, it's not even a match/replace, but it's more like a match/insert. Like in my example, "if the file name contains 'D2' (which it may not), insert '01' at the beginning of the file name". But it not only needs to do just that, but have many other insert strings depending on the match.

Trent R

Can't you use a command prompt to do this?

Actually, now that I think about it, your needs are probably too specific to use cmd.


~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

densming

I'm assuming this is Windows?  If so, you could use a for loop on the command prompt:

for %f in (*d2*) do ren "%f" "01%f"
for %f in (*d#2*) do ren "%f" "02%f"
...etc...

Be careful though, if you run this from a batch file (as opposed to directly from the command prompt), you'll need to use double percent signs:

for %%f in (*d2*) do ren "%%f" "01%%f"
for %%f in (*d#2*) do ren "%%f" "02%%f"
..etc..

Gregjazz

Thanks for the batch file help, densming.

After trying demos of at least 12 products, I just found this piece of software: http://www.coolutils.com/Article.php?Article=RenameFiles&from=AdWordsRenameFiles

It does exactly what I need, and also includes a scripting language as well.

Nikolas

I think that what you SEEM to be wanting to do is very very interesting. Share more, share more, share mutli more stuff please!  :D

Gregjazz

Basically what I'm doing is renaming sample file names from including a MIDI note name to having a numeric value as a suffix. That way when they get sorted alphabetically, they are sorted chromatically. This makes mapping sample libraries a LOT faster and easier.

BOYD1981

i used to use a brilliantly handy app called RenameWiz, it isn't free but i'm not sure if the trial version limits any functionality.
i tried some other batch renamers recently, but they were all crappy compared to RenameWiz.
http://www.renamewiz.com/

Limey Lizard, Waste Wizard!
01101101011000010110010001100101001000000111100101101111011101010010000001101100011011110110111101101011

Gregjazz

Quote from: densming on Sun 03/05/2009 05:31:16
I'm assuming this is Windows?  If so, you could use a for loop on the command prompt:

for %f in (*d2*) do ren "%f" "01%f"
for %f in (*d#2*) do ren "%f" "02%f"
...etc...

Be careful though, if you run this from a batch file (as opposed to directly from the command prompt), you'll need to use double percent signs:

for %%f in (*d2*) do ren "%%f" "01%%f"
for %%f in (*d#2*) do ren "%%f" "02%%f"
..etc..

I tried this, and it works to some degree. On a few files it placed "01 01" at the beginning rather than just "01". It shouldn't be finding multiple matches within each individual file name...

Snarky

I think computer pros generally do this kind of thing using regular expressions (kind of advanced pattern-matching). Perl is supposed to be pretty good for regex stuff, so you could install a Perl engine for windows and write a script in that language to do exactly what you want.

...Yeah, I know, it doesn't exactly sound quick and easy to me either.

zabnat

Quote from: Snarky on Mon 04/05/2009 03:41:14
I think computer pros generally do this kind of thing using regular expressions (kind of advanced pattern-matching). Perl is supposed to be pretty good for regex stuff, so you could install a Perl engine for windows and write a script in that language to do exactly what you want.

...Yeah, I know, it doesn't exactly sound quick and easy to me either.
It does sound quick and easy to me. Perl is awesome for that purpose. Only problem is that when you want to do the same thing in six months and want to change the script a bit, you have to write it from scratch because you have no idea what the code does you wrote six months ago. ;)

Snarky

Installing a Perl engine, learning a new programming language, and programming the rename operations yourself on the command line in generally incomprehensible syntax sounds easy?

zabnat

Quote from: Snarky on Wed 06/05/2009 20:01:22
Installing a Perl engine, learning a new programming language, and programming the rename operations yourself on the command line in generally incomprehensible syntax sounds easy?
Of course it does?
Installing is pressing the next button couple of times. Learning new programming language is easy if you know how to program. And then just google a ready made code for renaming files. ;)

monkey0506

#15
Quote from: zabnat on Thu 07/05/2009 08:05:44And then just google a ready made code for renaming files. ;)

Why not just do that for the batch file route? That avoids having to install Perl, worrying about having to learn the code, etc. and so-forth.

The batch file doesn't really have regex, but is there a reason to defer to a full programming language which Greg likely doesn't already have installed?

How many of the files were having duplicate prefixes added?

Would something like this work?

Code: ags
@echo off
SetLocal EnableDelayedExpansion
for %%f in (*d2*) do (
set name=%%f
set str=!name:~0,2!
if not !str!==01 ren "%%f" "01%%f"
)
for %%f in (*d#2*) do (
set name=%%f
set str=!name:~0,2!
if not !str!==02 ren "%%f" "02%%f"
)
EndLocal


I'm not sure if you can do substrings on the %%f, but that makes sure that each file only gets the prefix added once.

Edit: Apparently this requires delayed expansion. I've changed the code (tested now lol). I couldn't figure out any way to take a substring from %%f. And I was getting an error trying to use the substring directly in the if statement so that's why I put the additional variable.

Edit: Just wanted to put some info here from PMs between myself and Greg. For anyone unaware batch files treat very few things in a case sensitive manner so any patterns used by this batch file would have to be unique. One other option is that for Greg's use the patterns are always separated by whitespace. So if you have a whitespace character on either side you could make the pattern something such as:

Code: ags
for %%f in ("* d2 *") do (


You must enclose this pattern in quotes or it won't read the whitespace as part of the pattern. Just FYI for anyone reading this. ;)

Gregjazz

Densming's batch file worked, but we weren't able to find a way to disable 8.3 short file names, since I'm dealing with long file names only.

Basically with a few files it would "find the same file" more than once and execute the task multiple times, which gave the wrong results.

monkey0506

Did you test the modifications I made? That should prevent it from detecting the same files multiple times. If the file name already starts with "01" or "02" (or whatever) then it just gets ignored. Unless of course it contained multiple patterns...is that the problem?

goldensox

I use RenomearTudo. It sure rename everthing, make smart sequences and all. It's the photoshop of the filenames. :=
Faster than a doughnut, stronger than cardboard.
                                                                    -Wario

SMF spam blocked by CleanTalk