ReNamer:Pascal Script:Reuse variable

From den4b Wiki
Revision as of 14:56, 27 January 2013 by Stefan (talk | contribs) (just clean up a bit)
Jump to: navigation, search

This page is work in process!

If you want to store a variable to reuse the value later you can read here a few tips.


For examples you can store the last used path, folder or file name or parts of them.
Also you may want to store an index number, or perhaps a list of the original file names.



There are two main techniques to store variable values: use the registry or use a temporary file on disc.


First we take a look on the file approach.

We use simple plain text files to store the variable.

The ReNamer PascalScript functions to write and read text files are:

FileWriteContent( "FileName" , "Content" );
FileAppendContent( "FileName" , "Content" );

FileReadContent("FileName");
FileCountLines("FileName");
FileReadLine( "FileName" , LineNum );


For "FileName" you can just use a name without a path to store the file into the ReNamer folder.
Example:

FileWriteContent( "FileName.txt" , "Content" );
FileWriteContent( ".\FileName.txt" , "Content" );


To use an full path to your ReNamer folder use the ReNamer PascalScript function "GetApplicationPath"
Example:

FileWriteContent( WideExtractFilePath(GetApplicationPath) + "FileName.txt" , "Content" );


You can use your private temp (temporary) folder in your profile
by using the ReNamer PascalScript function "WideGetTempPath"
Example:

FileWriteContent( WideGetTempPath + "FileName.txt" , "Content" );


Also you can access all system environment variables by using "WideGetEnvironmentVar"
Example:

UserName := WideGetEnvironmentVar('USERNAME');



PascalScript rule examples

First rule in rule list:
(GET stored variable 'LastFolder')

var
  LastFold:string;

begin
 if(GetCurrentFileIndex=1)then
    if(WideFileExists(WideGetTempPath +'\den4b_LastFolder.txt')) then
        LastFold := FileReadContent(WideGetTempPath +'den4b_LastFolder.txt');

  //check if it works:
  ShowMessage(LastFold);
end.


Other rules here in between
-
-
-


Last rule in rule list:
(SET variable 'LastFolder' to stored for later reuse)

var
  ParentFold:string;

begin
 if(GetCurrentFileIndex=GetTotalNumberOfFiles)then
   begin
       ParentFold := CalculateMetaTag(FilePath, 'File_FolderName');
       FileWriteContent(WideGetTempPath + 'den4b_LastFolder.txt', ParentFold);
   end;
 
  //check if it works:
  ExecuteProgram('notepad ' + WideGetTempPath + 'den4b_LastFolder.txt',false);
end.


-#