Hi Agrox
I have experimented a bit. First I create a template for the master file and assign it to template index 0 -
Advanced - Display/Modify templates...It has the following contents:
- Code: Select all
File....: [FULL_FILE_NAME]
Red.....: $a
Blue....: $b,text
Yellow..: $c
Created.: [DATE_DMY] [TIME]
I chose template because I can then use the extra template variables for date, time and file info, like [TIME]. See the UE help for further explanations.
Then I created this script:
- Code: Select all
var numberOfGeneratedFiles = 2;
var filePath = "C:\\temp\\";
var filePrefix = "autoGenFileNo";
var fileExt = "txt";
var fullFilePath;
var parmVars;
var parmLow;
var parmHigh;
var parmValue;
setupVars();
for (f = 0; f < numberOfGeneratedFiles; f++) {
calculateVars();
UltraEdit.newFile();
fullFilePath = filePath+filePrefix+f+"."+fileExt;
UltraEdit.saveAs(fullFilePath); /* save as so we can utilize template variables like [FULL_FILE_NAME] */
UltraEdit.activeDocument.insertTemplate(0); /* now insert master file */
replaceVars();
// UltraEdit.closeFile(UltraEdit.activeDocument.path,1); /* save and close - uncomment */
UltraEdit.save();
}
/* ------------- */
function setupVars() {
parmVars = new Array();
parmLow = new Array();
parmHigh = new Array();
parmValue = new Array();
parmVars.push("a"); parmLow.push(10); parmHigh.push(19); parmValue.push(-1);
parmVars.push("b"); parmLow.push(100); parmHigh.push(999); parmValue.push(-1);
parmVars.push("c"); parmLow.push(1); parmHigh.push(1000); parmValue.push(-1);
}
/* ------------- */
function replaceVars() {
UltraEdit.activeDocument.findReplace.replaceAll=true;
for (i in parmVars) {
UltraEdit.activeDocument.findReplace.replace("$"+parmVars[i],""+parmValue[i]);
}
}
/* ------------- */
function calculateVars() {
for (i in parmVars) {
parmValue[i] = parmLow[i] + Math.floor(Math.random()*(parmHigh[i]-parmLow[i]));
}
}
You define how many generated files you want (2 in my example). The setupVars() function defines the variable and low and high limit for random numbers.
Then the script iterates to generate the number of files wanted. The template is inserted and it is searched/replaced for the variables. The variables are recalculated in each loop.
I hope this is an inspiration for you. With PHP experience I don't think it is too difficult to decipher. Otherwise have a look at the javascript resources linked in the
script sticky.
Only one thing I didn't consider for this solution: Large files of 60+MB. This might call for a slightly different solution than templates.