#1 2008-02-22 01:03

clapp
Member
Registered: 2008-02-21
Posts: 9

Export via script, serialize rule question

First, I wanted to say that the program has been extremely useful and thank you for creating it and putting it out there for everyone to use.

I had a couple of questions...

I would like to run Renamer strictly from a command line. I would like to use the export function... exporting both the old file name and the new file name to a .csv file... without having to use the options button. I have read an earlier post concerning a Pascal rule to export the new file name to the clipboard. Is a script possible to export both the old and the new? Could it go to a .csv or text file instead of the clipboard (via the script)? I am very novice at scripting and would greatly appreciate any guidance.

My other question... I would like to use the serialize rule, but would like to change the starting number... to a new (user defined) number everytime, without having to open and change the rule everytime I run the program. Is there a way to ask the user what number he/she would like to start at and feed that to the program somehow... before running the rename?

Thank-you for all of your time and help.

Last edited by den4b (2008-02-27 00:36)

Offline

#2 2008-02-27 00:42

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

Re: Export via script, serialize rule question

Thanks, clapp. Good to know that you find it very usefull smile

> Is a script possible to export both the old and the new, in script?
Yes, possible. FILEPATH constant holds the original path, and FILENAME variable holds the latest new name. You can export them both in any format you like, using PascalScript. But be aware of the performance drawbacks, as the rule will write to the disk after processing each file. Tell me if you need an example of the script, I will quickly write one for you.

> I would like to use the serialize rule, but would like to change the starting number
No, this is impossible. The new Serialize rule will always have the same starting index, i.e. 1. You will have to change the rule every time you want to change the starting index. OR, you can write another little script, which will do the same job as the Serialize, and you can tell it to start from any number, and even as user with a dialog.

Offline

#3 2008-02-27 06:59

clapp
Member
Registered: 2008-02-21
Posts: 9

Re: Export via script, serialize rule question

Thank you again... this is a great program... and thank you for responding back t my questons...

After looking through some of the other posts I modified one of the scripts to perform the serialization:

var
  I, J: Integer;
  Numbers, Pad, X: string;
  Initialized: Boolean;

begin
  if not Initialized then
  begin
    Initialized := True;
    Numbers := '0';
    // keep asking for a number from the user
  repeat
    if not InputQuery('Serialize script', 'What number do you want to start at?', X)
    then ShowMessage ('User cancelled the dialog');
  until X <> '';    
    I := 1; J := StrToInt(X);
  end;
  if I > Length(Numbers) then
  begin
    I := 1; J := J + 1;
  end;
  Pad := Numbers[i];
  if J > 0 then 
    Pad := IntToStr(J);
  FileName := Pad + WideExtractFileExt(FileName);  
  I := I + 1;
end.

This seems to perform what I want it to do... serialize at a (user) selected number, leaving the extension on. Please tell me if the code is o.k. or if there is a more efficient script that would do this... I just modified a script that I saw in one of the earlier posts.

Could you provide an example of the script to export both the original path/latest new name to a .csv file? I would be greatly appreciative of any help you could give. Thank you again for all your time and help with this. You have made a wondeful program.

Offline

#4 2008-02-27 07:21

clapp
Member
Registered: 2008-02-21
Posts: 9

Re: Export via script, serialize rule question

Sorry to keep asking for favors... this request may be in an earlier post as well. I was wondering if you could provide an example of a script to change the modified and created date/time of a file to a pre-chosen date/time. I am guessing that it would use the SetFileTimeCreated and SetFileTimeModified routines... but I'm not sure how to write the script. Is there also a way to change the date/time the file was last accessed? Thank you again for your help. smile

Offline

#5 2008-03-04 20:51

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

Re: Export via script, serialize rule question

Here is a slightly improved and cleaned up script, I hope it will be easy for you to read it.
It also has 2 small additions: dialog will initially display "1", and numbers will be padded to the "PADTO" length.

const
  PADTO = 3;
var
  Index: Integer;
  Value: String;
  Initialized: Boolean;
begin
  if not Initialized then
  begin
    Value := '1';  
    repeat
      if not InputQuery('Serialize Script',
        'What number do you want to start at?', Value)
      then ShowMessage ('User cancelled the dialog');
    until Value <> '';    
    Index := StrToInt(Value);
    Initialized := True;    
  end;
  Value := IntToStr(Index);
  if PADTO > 1 then
    while Length(Value) < PADTO do
      Value := '0'+Value;
  FileName := Value + WideExtractFileExt(FileName);  
  Index := Index + 1;
end.

And here is a demo script which will write FULLPATH and NEWNAME to the CSV file:

const
  COMMA = ',';
  NEWLINE = #13#10;
  CSV = 'C:\TEST.CSV';
var
  Initialized: Boolean;
  Content: WideString;
begin
  if not Initialized then
  begin
    Content := '';
    FileWriteContent(CSV, '');
    Initialized := True;
  end;
  Content := FilePath + COMMA + FileName + NEWLINE;
  FileAppendContent(CSV, Content);
end.

And below is another sample script, to demonstrate the usage of SetFileTimeModified function.
It is pointless to modify the "accessed time", because as soon as you modify it - it will be automatically
changed by the system to the current time, since you are accessing the file to cahnge the "accessed time" wink

var
  NewDate: TDateTime;
begin
  NewDate := EncodeDate(2007, 12, 30) + 
    EncodeTime(23, 59, 59, 0);
  SetFileTimeModified(FilePath, NewDate);
end.

NOTE: All these scripts are executed on every PREVIEW, and NEVER on RENAME.

Offline

#6 2008-03-07 01:18

clapp
Member
Registered: 2008-02-21
Posts: 9

Re: Export via script, serialize rule question

Thank-you very much for all of your help!:D
The program is great!!!

Offline

Board footer

Powered by FluxBB