Difference between revisions of "ReNamer:Pascal Script:Reuse variable"

From den4b Wiki
Jump to: navigation, search
(First content collection - work in process)
 
m (just clean up a bit)
Line 1: Line 1:
 
== This page is work in process!==
 
== 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.
 
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.
+
 
 +
For examples you can store the last used path, folder or file name or parts of them.<br>
 
Also you may want to store an index number, or perhaps a list of the original file names.
 
Also you may want to store an index number, or perhaps a list of the original file names.
 +
<br>
 +
<br>
 +
<br>
  
  
Line 11: Line 16:
  
  
First we take a look on the file approach.
+
==First we take a look on the file approach.==
  
 
We use simple plain text files to store the variable.
 
We use simple plain text files to store the variable.
  
 
The ReNamer PascalScript functions to write and read text files are:
 
The ReNamer PascalScript functions to write and read text files are:
 
+
<source>
 
FileWriteContent( "FileName" , "Content" );
 
FileWriteContent( "FileName" , "Content" );
 
FileAppendContent( "FileName" , "Content" );
 
FileAppendContent( "FileName" , "Content" );
Line 23: Line 28:
 
FileCountLines("FileName");
 
FileCountLines("FileName");
 
FileReadLine( "FileName" , LineNum );
 
FileReadLine( "FileName" , LineNum );
 +
</source>
  
  
 
+
For "FileName" you can just use a name without a path to store the file into the ReNamer folder.<br>
For "FileName" you can just use a name without a path to store the file into the ReNamer folder.
 
 
Example:
 
Example:
 +
<source>
 
FileWriteContent( "FileName.txt" , "Content" );
 
FileWriteContent( "FileName.txt" , "Content" );
 
FileWriteContent( ".\FileName.txt" , "Content" );
 
FileWriteContent( ".\FileName.txt" , "Content" );
 +
</source>
  
  
  
 
+
To use an full path to your ReNamer folder use the ReNamer PascalScript function "GetApplicationPath"<br>
To use an full path to your ReNamer folder use the ReNamer PascalScript function "GetApplicationPath"
 
 
Example:
 
Example:
 +
<source>
 
FileWriteContent( WideExtractFilePath(GetApplicationPath) + "FileName.txt" , "Content" );
 
FileWriteContent( WideExtractFilePath(GetApplicationPath) + "FileName.txt" , "Content" );
 +
</source>
  
  
  
 
+
You can use your private temp (temporary) folder in your profile<br>
You can use your private temp (temporary) folder in your profile
+
by using the ReNamer PascalScript function "WideGetTempPath"<br>
by using the ReNamer PascalScript function "WideGetTempPath"
 
 
Example:
 
Example:
 +
<source>
 
FileWriteContent( WideGetTempPath + "FileName.txt" , "Content" );
 
FileWriteContent( WideGetTempPath + "FileName.txt" , "Content" );
 +
</source>
  
  
 
+
Also you can access all system environment variables by using "WideGetEnvironmentVar"<br>
Also you can access all system environment variables by using "WideGetEnvironmentVar"
 
 
Example:
 
Example:
  UserName := WideGetEnvironmentVar('USERNAME');
+
<source>
 +
UserName := WideGetEnvironmentVar('USERNAME');
 +
</source>
  
  
Line 57: Line 67:
 
== PascalScript rule examples ==
 
== PascalScript rule examples ==
  
 
+
First rule in rule list:<br>
 
 
First rule in rule list:
 
 
(GET stored variable 'LastFolder')
 
(GET stored variable 'LastFolder')
 
<source>
 
<source>
Line 76: Line 84:
  
  
 +
Other rules here in between<br>
 +
-<br>
 +
-<br>
 +
-<br>
  
Last rule in rule list:
+
 
 +
Last rule in rule list:<br>
 
(SET variable 'LastFolder' to stored for later reuse)
 
(SET variable 'LastFolder' to stored for later reuse)
 
<source>
 
<source>
Line 91: Line 104:
 
   
 
   
 
   //check if it works:
 
   //check if it works:
   ExecuteProgram('notepad ' + WideGetTempPath + '\den4b_LastFolder.txt',false);
+
   ExecuteProgram('notepad ' + WideGetTempPath + 'den4b_LastFolder.txt',false);
 
end.
 
end.
 
</source>
 
</source>
  
  
#
+
 
 +
-#

Revision as of 13:56, 27 January 2013

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.


-#