April 20, 2009 at 11:01 pm #7166
Yutaka Emura
Keymaster
This is my sample to check if
matches in all HTML files in a folder (searches the folder recursively). You would of course need to modify the root folder, the contents of DoSomething() function, and the file extension to search.
sRootDir = "E:help..."; // root folder
editor.NewFile();
var docResult = editor.ActiveDocument;
docResult.writeln( "ERRORS Root Folder: " + sRootDir );
Redraw = false;
var nTotalFiles = EnumerateFolder( sRootDir );
Redraw = true;
alert( "Finished successfully. Total of " + nTotalFiles + " files processed." );
function EnumerateFolder( sFolder )
{
var nTotal = 0;
var fso, f, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(sFolder);
fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext())
{
sItem = String( fc.item() );
nLen = sItem.length;
if( sItem.indexOf( "_" ) == -1 && sItem.substr( nLen - 4 ) == ".htm" ){ // make sure file or folder does not begin with _ and the file extension is .htm.
DoSomething( sItem );
nTotal++;
}
}
fc = new Enumerator(f.SubFolders);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
sItem = String( fc.item() );
nLen = sItem.length;
if( sItem.indexOf( "_" ) == -1 ){ // make sure folder name does not begin with _
nTotal += EnumerateFolder( sItem );
}
}
return nTotal;
}
function DoSomething( sPath )
{
var y = 0;
editor.OpenFile( sPath, 0, eeOpenAllowNewWindow );
document.selection.Find( "(?<=<title>).+?(?=</title>)", eeFindNext | eeFindAround | eeFindReplaceRegExp | eeFindReplaceQuiet );
sTitle = document.selection.Text;
if( sTitle.length != 0 ){
y = document.selection.GetTopPointY( eePosLogical );
}
else {
y = document.selection.GetActivePointY( eePosLogical );
}
document.selection.Find( "(?<=<h2>).+?(?=</h2>)", eeFindNext | eeFindAround | eeFindReplaceRegExp | eeFindReplaceQuiet );
sH = document.selection.Text;
document.close();
if( sH.substr( 0, 3 ) == "Q. " ){
sH = sH.substr( 3 );
}
if( sTitle.length == 0 || sH.length == 0 || sTitle.indexOf( sH ) == -1 ){
docResult.Activate();
document.writeln( "" + sPath + "(" + y+1 + "):" );
document.writeln( "t<title> " + sTitle );
document.writeln( "t<h2> " + sH );
document.writeln( "" );
}
}
sRootDir = "E:help..."; // root folder
editor.NewFile();
var docResult = editor.ActiveDocument;
docResult.writeln( "ERRORS Root Folder: " + sRootDir );
Redraw = false;
var nTotalFiles = EnumerateFolder( sRootDir );
Redraw = true;
alert( "Finished successfully. Total of " + nTotalFiles + " files processed." );
function EnumerateFolder( sFolder )
{
var nTotal = 0;
var fso, f, fc, s;
fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.GetFolder(sFolder);
fc = new Enumerator(f.files);
for (; !fc.atEnd(); fc.moveNext())
{
sItem = String( fc.item() );
nLen = sItem.length;
if( sItem.indexOf( "_" ) == -1 && sItem.substr( nLen - 4 ) == ".htm" ){ // make sure file or folder does not begin with _ and the file extension is .htm.
DoSomething( sItem );
nTotal++;
}
}
fc = new Enumerator(f.SubFolders);
s = "";
for (; !fc.atEnd(); fc.moveNext())
{
sItem = String( fc.item() );
nLen = sItem.length;
if( sItem.indexOf( "_" ) == -1 ){ // make sure folder name does not begin with _
nTotal += EnumerateFolder( sItem );
}
}
return nTotal;
}
function DoSomething( sPath )
{
var y = 0;
editor.OpenFile( sPath, 0, eeOpenAllowNewWindow );
document.selection.Find( "(?<=<title>).+?(?=</title>)", eeFindNext | eeFindAround | eeFindReplaceRegExp | eeFindReplaceQuiet );
sTitle = document.selection.Text;
if( sTitle.length != 0 ){
y = document.selection.GetTopPointY( eePosLogical );
}
else {
y = document.selection.GetActivePointY( eePosLogical );
}
document.selection.Find( "(?<=<h2>).+?(?=</h2>)", eeFindNext | eeFindAround | eeFindReplaceRegExp | eeFindReplaceQuiet );
sH = document.selection.Text;
document.close();
if( sH.substr( 0, 3 ) == "Q. " ){
sH = sH.substr( 3 );
}
if( sTitle.length == 0 || sH.length == 0 || sTitle.indexOf( sH ) == -1 ){
docResult.Activate();
document.writeln( "" + sPath + "(" + y+1 + "):" );
document.writeln( "t<title> " + sTitle );
document.writeln( "t<h2> " + sH );
document.writeln( "" );
}
}