You are not logged in.
First of all, this is my first post and I must say that ReNamer looks to be a great tool! I have tried many such mass renaming tools but not one so far has managed to do what I want successfully. Maybe ReNamer can do the trick!
Ok, here's what I want to do... I have a bunch of files to which I want to append the months and years sequentially.
So,
Report_001.xls
Report_002.xls
...
Report_UVW.xls
Report_XYZ.xls
should become
Report_001_Jan_2008.xls
Report_002_Feb_2008.xls
...
Report_UVW_Jan_2009.xls
Report_XYZ_Feb_2009.xls
[Ideally, I should be able to specify if I want Jan/Feb/... or January/February/..., and 08/09/... or 2008/2009/...]
Note that this presents a lot of challenges, including incrementing the month across files (the month/year in the name might not be the same as in the file's date stamp) and also incrementing the year only when we cross December.
I'm not too sure that any mass renamer out there can do this, but if one can, it might well be ReNamer due to features like PascalScript, RegEx etc.
Can someone tell me if this is even possible or if not, maybe it can be added to the feature list without putting undue pressure on Denis, who has put in much sweat and effort in order to help others without asking for anything in return. Thanks a bunch Denis!
Offline
It is possible.
To be honest with ReNamer almost everything is possible in the case of batch renaming.
It will need a not very complicated PascalScript.
Stay tuned
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline
Here you go needed PascalScript.
const PADTO = 2;
var
Year, Month: Integer;
Initialized: Boolean;
Months : Array of String;
Separator, StrYear: String;
begin
//INITIALIZATION (only once for whole renaming operation)
if not Initialized then
begin
//Initialization of nessecary variables
Separator:='_';
// Months:=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
Months:=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Month:=StrToInt(InputBox('Month', 'Which month should we start with?', '1'));
Year:= StrToInt(InputBox('Year', 'Which year should we start with?', '08'));
Initialized := True;
end;
//END OF INITIALIZATION
StrYear := IntToStr(Year);
while Length(StrYear) < PADTO do
StrYear := '0'+StrYear;
FileName := WideExtractBaseName(FileName) + Separator + Months[Month-1]+ Separator + StrYear +WideExtractFileExt(FileName);
if Month = 12 then
begin
Year:=Year+1;
Month:=1;
end
else Month:=Month+1;
end.
You can customize it by changing these lines:
Separator:='_';
// Months:=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
Months:=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
It's set to use short names of months now. If you want long names you should uncomment first assignment for Months, and comment out the second one, like this:
Months:=['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
// Months:=['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
And Separator is used to separate parts of filename. If you prefer space or anything else, just put it inside apostrophes ' '.
Script reacts on wether you give it 08 (or simply 8) or 2008 as a year.
Cheers,
Konrad
Last edited by krtek (2008-05-24 01:09)
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline
Dang! Konrad, I must say, you're a bonafide, certifiable Genius with a Capital 'G'!
That code is amazing and works superbly! Hats off to Denis as well. ReNamer officially rocks!
Offline
I'm glad that you finally found your solution Andrew!
P.S. Great job there, krtek! Thanks for help, once again
Offline
I've finally found out how to use PascalScripts
Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).
Offline
I cleaned it up slightly, and made configuration of the short years and months to be constants, so they can be easily modified at the top of the script. Set SHORT_MONTHS and SHORT_YEARS to "True" or "False", whether you need short or long format of the months and years.
Note: No error checking is done, so make sure that you enter 1-12 values in the months dialog, and a 4 digit year in the years dialog.
const
SEPARATOR = '_';
SHORT_MONTHS = False;
SHORT_YEARS = False;
var
Year, Month: Integer;
Initialized: Boolean;
MonthsLong, MonthsShort: Array of String;
StrYear, StrMonth: String;
begin
if not Initialized then
begin
MonthsLong := ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'];
MonthsShort := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
Month := StrToInt(InputBox('Month', 'Which month should we start with? (1-12 values)', '1'));
Year := StrToInt(InputBox('Year', 'Which year should we start with? (4 digits)', '2008'));
Initialized := True;
end;
StrYear := IntToStr(Year);
if SHORT_YEARS then
StrYear := Copy(StrYear, 3, 2);
if SHORT_MONTHS then
StrMonth := MonthsShort[Month-1]
else
StrMonth := MonthsLong[Month-1];
FileName := WideExtractBaseName(FileName) + Separator +
StrMonth + Separator + StrYear +WideExtractFileExt(FileName);
if Month < 12 then
Month := Month + 1 else
begin
Year := Year + 1;
Month := 1;
end;
end.
Offline
Denis, that's great. I had already modified the code to make it a bit more robust, and also to take care of other situations where I wanted names with "Jan-Feb", "Mar-Apr" etc. It's easy once the framework is in place, thanks to you and Konrad! I'm also getting to slowly know the PascalScript functions better so that I can experiment a bit more. BTW, is there any function to check if a number is valid, so that the user can't enter letters in place of months/years?
I must say that including PascalScript support is nothing short of sheer genius, as it makes the program (almost) infinitely extendable without a lot of additional effort on your behalf. BTW, which version of PascalScript is included in the program? Is it the latest?
In fact, since PascalScript is so powerful, I even thought that maybe all the different renaming functions could be implemented using it? So for example instead of having different rules for delete, remove, replace etc. whose code is hidden, one could change it so that on selecting any of these options, the corresponding PascalScript code is generated on-the-fly. This would enable users to easily modify/extend the code whenever required.
Also, instead of people like you and Konrad posting scripts here and there in reply to queries like mine, maybe you can have a separate section of the site devoted to user-written scripts that anyone can download and use? Such an online searchable script library would be an invaluable resource and also reduce repeat requests for the same code, don't you think? As an incentive, script authors could be credited so that selecting their scripts would show their names in the program. Everyone wants to be famous after all!
Thanks for everything,
Andrew
Last edited by Andrew (2008-05-29 17:57)
Offline
is there any function to check if a number is valid?
Actually, there are several ways to check this:
1) Use StrToIntDef() function, where you can define a default value in case specified value is not a number. So you can use StrToIntDef(Value, -1), and check if the return is "-1" - which will tell you that the specified value was not numeric (unless user actually specified "-1", which is not a valid value for you anyway).
2) Use "try ... except ... end" to catch any conversion errors from StrToInt() function.
3) Use MatchesRegEx() to do complex verifications using regular expressions.
which version of PascalScript is included in the program? Is it the latest?
I think I use v3.0.27.651 at the moment. It is not the latest, but fairly recent one. Why?
maybe all the different renaming rules could be implemented using PascalScript?
Yes, they could be. But most of the users will be much happier with standard GUI rules.
a separate section of the site devoted to user-written scripts that anyone can download and use?
Ahh, yeh. Few people already suggested this, and here is what I think: it's a great idea, but I don't have time to maintain and moderate this kind of section. You can probably find all written scripts by searching forums with something like "PascalScript" or "begin AND end".
Offline
Actually, there are several ways to check this:
1) Use StrToIntDef() function, where you can define a default value in case specified value is not a number. So you can use StrToIntDef(Value, -1), and check if the return is "-1" - which will tell you that the specified value was not numeric (unless user actually specified "-1", which is not a valid value for you anyway).
Thanks! This was just what the doctor ordered.
I think I use v3.0.27.651 at the moment. It is not the latest, but fairly recent one. Why?
No real reason. Just thought that the latest stable version should have bug fixes and/or new features that would come in handy, so why not use it?
Ahh, yeh. Few people already suggested this, and here is what I think: it's a great idea, but I don't have time to maintain and moderate this kind of section. You can probably find all written scripts by searching forums with something like "PascalScript" or "begin AND end".
Hmm... Well IMO the section would not really need a great deal of moderation per se... It would just be a sort of common dumping ground for user-written scripts to make it easier to browse through them instead of searching in the forums. Anyway, I respect your decision in this regard.
Offline