OK Mofi, I think I'm getting much better at this!
Your code you gave me was great for incrementing the tocvalue now I need to make a comparison script. What I'm trying to do is take in a string that has 3 parameters, file name, title, toclevel. I have a file which has this data on each line for each file 350+ files.
So the script grabs the line, splits the parameters using the comma, and places each into an array which i then place into variables. I use these variable to first open the file, find the title, and replace the toclevel. If the title doesn't match I need to output the name of the file to the output window or a text file for further review (still working on this part).
Right now this script cycles through the list of files and opens it, but it doesn't do anything. Can you please explain to me what I'm doing wrong?
Thank you,
Max
Code: Select all
UltraEdit.insertMode();
if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
UltraEdit.perlReOn();
var nXmlFile = 0;
var nListFile = 0;
var sSplit = "";
var sFileName = "";
var sTitle = "";
var sDocLvl = "";
UltraEdit.activeDocument.top();
while (nListFile < UltraEdit.document.length) {
if (UltraEdit.document[nListFile].path == UltraEdit.activeDocument.path) break;
nListFile++;
}
while (!UltraEdit.activeDocument.isEof()) {
// Select everything from the beginning of the line to the end of the line.
UltraEdit.activeDocument.startSelect();
UltraEdit.activeDocument.key("END");
sSplit = UltraEdit.activeDocument.selection;
UltraEdit.activeDocument.endSelect();
UltraEdit.activeDocument.key("HOME");
UltraEdit.activeDocument.key("DOWN ARROW");
/* I need to slice this string into 3 parameters using the comma as the
parameter indicator.
param 1 = sFileName;
param 2 = sTitle;
param 3 = sDocLvl;
*/
var sTocArray = sSplit.split(',');
sFileName = sDocArray[0];
sTitle = sDocArray[1];
sDocLvl = sDocArray[2];
for (nXmlFile = 0; nXmlFile < UltraEdit.document.length; nXmlFile++) {
if (UltraEdit.document[nXmlFile].path == sFileName) break;
}
if (nXmlFile < UltraEdit.document.length) UltraEdit.document[nXmlFile].setActive();
else UltraEdit.open(sFileName);
UltraEdit.activeDocument.top();
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.mode=0;
UltraEdit.activeDocument.findReplace.matchCase=true;
UltraEdit.activeDocument.findReplace.matchWord=false;
UltraEdit.activeDocument.findReplace.regExp=true;
if (UltraEdit.activeDocument.findReplace.find(sTitle)) {
UltraEdit.activeDocument.endSelect();
UltraEdit.activeDocument.key("LEFT ARROW");
UltraEdit.activeDocument.findReplace.searchDown=false;
UltraEdit.activeDocument.findReplace.find("level='\\d+'");
UltraEdit.activeDocument.findReplace.searchDown=true;
UltraEdit.activeDocument.findReplace.replaceAll=false;
UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
UltraEdit.activeDocument.findReplace.selectText=false;
UltraEdit.activeDocument.findReplace.preserveCase=false;
UltraEdit.activeDocument.findReplace.replace("level ='\\d+'", sDocLvl);
UltraEdit.closeFile(UltraEdit.activeDocument.path,1);
}
else UltraEdit.closeFile(UltraEdit.activeDocument.path,2);
UltraEdit.document[nListFile].setActive();
}
Text file with list of files and strings
Code: Select all
test.xml,title='asdfawefaw', level ='3'
test1.xml,title='test test test', level ='9'
test2.xml,title='test test5 test', level ='3'
test3.xml,title='test test test', level ='5'
test4.xml,title='test4 test test', level ='2'
Sample text file:
Code: Select all
title='test test test' level ='4'
title='test test5 test' level ='1'
title='test test test', level ='2'