#1 2009-01-25 16:06

Walk Softly
Member
Registered: 2009-01-25
Posts: 4

Pascal Script: change time/date *of* file

It's an interesting feature to insert date- time into filename, but how would one use the pascal script to change the OS  (XP Pro SP3) system date and time OF the file(s)?

var
  DateTime: TDateTime;

begin
  DateTime := FileTimeModified(FilePath);
  FileName := WideExtractBaseName(FileName) +
    FormatDateTime(' (06-Jan-2009)', DateTime) +
    WideExtractFileExt(FileName);
end.

Offline

#2 2009-01-25 17:26

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Pascal Script: change time/date *of* file

Did you have a look at the help file? roll If you had, you might have spotted these functions:

function SetFileTimeCreated(const FileName: WideString; const DateTime: TDateTime): Boolean;

function SetFileTimeModified(const FileName: WideString; const DateTime: TDateTime): Boolean;

Offline

#3 2009-01-29 17:49

Walk Softly
Member
Registered: 2009-01-25
Posts: 4

Re: Pascal Script: change time/date *of* file

smile thanks for your reply

Not being a programmer the reference, quoted or otherwise, only served to irk me.

Where could I find an example script using these features?  It need not be exactly what I was looking for.

In the mean time I shall continue to use Flexible Renamer instead neutral

* scratch that where.  This http://www.den4b.com/forum/viewtopic.php?id=156 will take too much tinkering for me.  sad

** this works http://www.den4b.com/forum/viewtopic.php?id=341  but how could I have ReNamer prompt for the dates/times instead of manually editing the script each time.  Flexible Renamer is still much easier to batch re-time and re-date files.


I do adore ReNamer but I also need less painful time/date modification

somemodga3.png

I do not use flexible renamer for anything other than time/date modification

Last edited by Walk Softly (2009-01-29 18:03)

Offline

#4 2009-01-29 20:47

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Pascal Script: change time/date *of* file

Do you want ReNamer to prompt for a date-time for every file or only once on the initialization of the script (and then use that date-time for all the files)?

In any of these examples you might need one of these functions:

function WideInputBox(const ACaption, APrompt, ADefault: WideString): WideString;
function WideInputQuery(const ACaption, APrompt: WideString; var Value: WideString):
Boolean;
function InputBox(const ACaption, APrompt, ADefault: String): String;
function InputQuery(const ACaption, APrompt: String; var Value: String): Boolean;


You might try that script (it's completely harmless, it only shows you how to ask about date). You would need also some input check for correctness, but I hope you'll cope with that.

const
Delimiter = '-';

var 
Value : WideString;
Date : TStringsArray;
Initialized: Boolean;

procedure Initialize;
begin
  Initialized := True;
  if WideInputQuery('Give me a date:', 'DD'+Delimiter+'MM'+Delimiter+'YY', Value) = True then
  Date:=WideSplitString(Value, Delimiter);
  
end;

//main part of the script
begin
  if not Initialized then Initialize;

ShowMessage('Day: '+Date[0]+#13+'Month: '+Date[1]+#13+'Year: '+Date[2]);

end.

Check out ReNamer's Manual for more.

Last edited by krtek (2009-01-29 21:07)


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

#5 2009-01-30 17:26

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Pascal Script: change time/date *of* file

Walk Softly wrote:

Not being a programmer the reference, quoted or otherwise, only served to irk me.

Ok, no offence, but you come up with a PascalScript query, and then paste a piece of code as well, so how am I supposed to know that you're not a programmer? All I thought was, "he knows enough to write this code, so surely he must have read the Help file that comes with ReNamer and will know how to use these two functions".

I wish that instead of asking "how would one use the pascal script to change the OS  (XP Pro SP3) system date and time OF the file(s)?", you'd have straight away asked us that you're looking for a script that changes the date/time of files/folders, either by asking for input for every file/folder, or only once at the beginning. That would have been so simple and to the point. Anyway, now you have krtek's script to help you out as a starting point for further modification, if you're so inclined.

Walk Softly wrote:

In the mean time I shall continue to use Flexible Renamer instead neutral

I do not use flexible renamer for anything other than time/date modification

Frankly, I feel you're going about it all wrong. While one can, one generally doesn't use a sledgehammer to drive in a nail, right? Similarly, while PascalScript can be used to do a whole lot of things, it doesn't always make sense to do so. It doesn't matter if you're using Flexible Renamer or Denis' ReNamer or any other renaming utility in the world. Point is, they are renaming utilities! If all you want to do is change the date/time of files/folders, you may be better off with a program that does just that, don't you think? There are any number of utilities that will do that, both paid and free. A simple Google search threw up hundreds. Why don't you use something like the following?

http://www.nirsoft.net/utils/filedatech.html

It's free, only 20KB, requires no install and is custom-built to do only what you want and nothing else, which I think will serve your purpose a whole lot better than writing PascalScript just for this.

Last edited by Andrew (2009-01-30 17:38)

Offline

#6 2009-01-31 11:49

Walk Softly
Member
Registered: 2009-01-25
Posts: 4

Re: Pascal Script: change time/date *of* file

krtek wrote:

only once on the initialization of the script (and then use that date-time for all the files)?

I would much prefer that second option.


You might try that script

Hopefully I shall reach the point of being self sufficient soon.  Thanks



/me dons flame retardant

Andrew wrote:

Ok, no offence,

That notice typically indicates the opposite.


how am I supposed to know

My mistake.  Please accept my apologies.

While one can, one generally doesn't use a sledgehammer to drive in a nail, right?

overkill is the ReNamer way wink  One is more likely to achieve MacGyveresque aspirations with overkill.


they are renaming utilities!

* Integrated Windows XP Manifest to allow visual styling;
* Added Base64Encode and Base64Decode functions to PascalScript



you may be better off with a program that does just that, don't you think?

http://support.microsoft.com/kb/320167


thank you for taking the time to reply- and find that big_smile

I shall endeavor to be less circuitous in my next support request.

cheers

Offline

#7 2009-01-31 18:30

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: Pascal Script: change time/date *of* file

Walk Softly wrote:

I would much prefer that second option.

I thought so. And that's what the script posted by me earlier does. It asks you for date in initialization part and then uses that information to show (only show..) that date for every file in the filetable...
All you have to do is changing

ShowMessage('Day: '+Date[0]+#13+'Month: '+Date[1]+#13+'Year: '+Date[2]);

into something like this (you'll need new var NewDate: TDateTime):

NewDate:=EncodeDate(StrToInt(Date[2]),StrToInt(Date[1]),StrToInt(Date[0]));
SetFileTimeCreated(FileName; NewDate);

or simplier:

NewDate:=StrToDate(Value);
 SetFileTimeCreated(FileName; NewDate);

In the second opion you don't even need the line

Date:=WideSplitString(Value, Delimiter);

but I don't know how the input string of the date should look like (probably dd.mm.yyyy).


But what you are going to do is to CHANGE date of creation of all the files to one given to the script EVERY time you press PREVIEW (not Rename...).
So use it wisely...

Last edited by krtek (2009-01-31 18:34)


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

#8 2009-02-01 07:48

Andrew
Senior Member
Registered: 2008-05-22
Posts: 542

Re: Pascal Script: change time/date *of* file

Walk Softly wrote:

That notice typically indicates the opposite.

Heh. Yeah, generally it does, doesn't it? wink However, in this case I genuinely meant to give no offence, but if the receiver takes offence, then that's his prerogative and I can't really do anything about it now, can I? Anyway, let's stop quibbling over grammar and semantics and move on... smile

Walk Softly wrote:

* Integrated Windows XP Manifest to allow visual styling;
* Added Base64Encode and Base64Decode functions to PascalScript

Well, I would typically start off by noting that nowadays, styles/skins etc. are (IMO) a superfluous plague that seem to affect all types of utilities in general. But let me stop right there, for I don't want to be sucked into defending Denis' decisions regarding his own software.

I wrote that IMO, a renaming utility should not be used for simply changing the date/time of files (especially if, as you say, that's the only use it is put to). Even in that other utility, I'm sure it was only a small add-on by the author implemented in his spare time or something. Anyway, if you want to use it to do just this, go right ahead. No one's stopping you! roll

Finally, if you've managed to cobble together the required script using krtek's great suggestions, then that's fantastic, else do get back to us here. However, some quick points to note:

  • Unlike Flexible Renamer that has a purpose-built UI for date acceptance, ReNamer has none and so one would use a simple textbox. This leads to the problem of incorrect date format being entered by the user, which needs to be handled by the script.

  • The date format may be correct, but the date itself may be wrong. So the script has to check whether the year, month and day are within limits or not. It would also have to check for leap years so that February is handled correctly.

  • If you need to set the same date for both creation and modification, then it's simpler. Else like Flexible Renamer, if you want to set different dates, you'd need the script to handle this accordingly.

  • As krtek noted, the file times would be changed on every preview, so one needs to be extra careful.

  • I don't know how Flexible Renamer handles it, but I suppose that since it provides in-built support for this function, it also provides an Undo feature for the same. With PascalScript however, there is no undo possible, so if you make a mistake with your files, well, there's no going back.

As you can see, things are never as easy as they seem, and scripts can quickly get out of hand. It is due to these (and no doubt other) issues that I recommended that you use a purpose-built utility (or even Flexible Renamer itself) to do this task, and use ReNamer for all your renaming purposes. So kindly ask yourself why exactly you want to use PascalScript here and then proceed only if you're absolutely convinced that it will provide some advantage sufficient enough to offset all that work involved.

Offline

#9 2009-02-01 13:56

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,375

Re: Pascal Script: change time/date *of* file

I agree with Andrew's post. ReNamer can do loads of different things, especially with the power of PascalScript. But one must not forget that the purpose of ReNamer is to rename files. All other things like changing the date-time of files, changing the content of files, even executing other applications - also can be done, but are not the main purpose of ReNamer.

Walk Softly, your task can be achieved with a use of PascalScript, but, as you already found out, it is not very straight forward and easy as you wanted. Maybe it would be better for you to use a dedicated tool created especially for changing date-time of files.

Whichever way you pick, tell us how it goes...

Offline

Board footer

Powered by FluxBB