Adventure Game Studio

Community => General Discussion => Topic started by: Gregjazz on Sun 03/05/2009 01:56:32

Title: Looking for batch file renamer
Post by: Gregjazz on Sun 03/05/2009 01:56:32
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.
Title: Re: Looking for batch file renamer
Post by: Leon on Sun 03/05/2009 02:50:31
I use the BulkRenameUtility (http://www.bulkrenameutility.co.uk/Main_Intro.php).
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.)
Title: Re: Looking for batch file renamer
Post by: AGA on Sun 03/05/2009 03:02:33
I use AF5 (http://www.fauland.com/af5.htm). It has a few more sophisticated functions that I never bothered working out how to use, so it might work.
Title: Re: Looking for batch file renamer
Post by: Gregjazz on Sun 03/05/2009 03:21:17
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.
Title: Re: Looking for batch file renamer
Post by: Trent R on Sun 03/05/2009 04:58:32
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
Title: Re: Looking for batch file renamer
Post by: 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..
Title: Re: Looking for batch file renamer
Post by: Gregjazz on Sun 03/05/2009 05:48:30
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.
Title: Re: Looking for batch file renamer
Post by: Nikolas on Sun 03/05/2009 17:18:58
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
Title: Re: Looking for batch file renamer
Post by: Gregjazz on Mon 04/05/2009 01:41:15
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.
Title: Re: Looking for batch file renamer
Post by: BOYD1981 on Mon 04/05/2009 02:04:19
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/
Title: Re: Looking for batch file renamer
Post by: Gregjazz on Mon 04/05/2009 02:53:40
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...
Title: Re: Looking for batch file renamer
Post by: 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.
Title: Re: Looking for batch file renamer
Post by: zabnat on Tue 05/05/2009 20:06:14
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. ;)
Title: Re: Looking for batch file renamer
Post by: 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?
Title: Re: Looking for batch file renamer
Post by: zabnat on Thu 07/05/2009 08:05:44
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. ;)
Title: Re: Looking for batch file renamer
Post by: monkey0506 on Thu 07/05/2009 18:30:06
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?

@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:

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. ;)
Title: Re: Looking for batch file renamer
Post by: Gregjazz on Thu 07/05/2009 21:09:55
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.
Title: Re: Looking for batch file renamer
Post by: monkey0506 on Fri 08/05/2009 06:36:28
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?
Title: Re: Looking for batch file renamer
Post by: goldensox on Sat 09/05/2009 07:25:41
I use RenomearTudo. It sure rename everthing, make smart sequences and all. It's the photoshop of the filenames. :=