I found a way to do it, I've pasted it here in case anyone else needs it.
<HTML>
<HEAD>
<META name="GENERATOR" content="Microsoft FrontPage 4.0">
<META name="ProgId" content="FrontPage.Editor.Document">
<TITLE>Properties Parser</TITLE>
<!--
Insert Copyright HTML Application
Written by Keith Lofy
-->
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Insert Copyright"
BORDER="thick"
CAPTION="yes"
ICON="w_icon.gif"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="yes"
>
<SCRIPT LANGUAGE="JavaScript">
var ForReading = 1;
var ForWriting = 2;
var ForAppending = 8;
var TriStateFalse = 0;
var OriginalLine = "";
var SplitLine = "";
var ModifiedLine = "";
var sFilePathName = "";
var sModifiedFilePathName = "";
var outputtext = "";
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var f = FSO.GetFolder("C:/Documents and Settings/My Documents/CopyrightReplace");
var count = 0;
var copyright1 = "/*";
var copyright2 = "* ";
var copyright3 = "* June 18, 2004";
var copyright4 = "* Copyright 2004, SBC Communication Inc. All rights reserved.";
var copyright5 = "* This copyrighted material is the Confidential, Unpublished Property ";
var copyright6 = "* of SBC Communications Inc. ";
var copyright7 = "*/";
function trim(str) {
str.replace(/^\s*/, '').replace(/\s*$/, '');
return str;
}
//Recursion
function myRecursion(){
try{
IterateThroughDirectory(f);
alert("File Count is : " + count + "\n" + "output text is: " + outputtext);
// Destroy and de-reference FileSystemObject
delete objTextSteam
objTextStream = null;
delete FSO;
FSO = null;
alert("Converstion Completed.");
} catch(e){
alert("An error occured in: myRecursion(), the error was: " + e.description)
}
}
function IterateThroughDirectory(objFolder)
{
try{
// Get enumerator for files in directory
var fe = new Enumerator(objFolder.Files);
// Check to see if file is a .java file
for (;!fe.atEnd();fe.moveNext()){
if(fe.item().type == "JAVA File"){
outputtext = outputtext + "File Name: " + fe.item().path + "." + fe.item().name + " \n";
count++;
AddJavaCopyright(fe.item());
}
}
// now that each file in the folder has been processed repeat sequence for all subdirectories
var fsubf = new Enumerator(objFolder.SubFolders);
for (i=0; !fsubf.atEnd(); fsubf.moveNext()){
IterateThroughDirectory(fsubf.item())
}
} catch(e){
alert("An error occured in: IterateThroughDirectory(), the error was: " + e.description)
}
}
function AddJavaCopyright(fe){
var originalFileName = fe.name;
var originalFilePath = fe.path;
var modifiedFileName = originalFileName.replace(new RegExp("\.java"), "new.java");
var modifiedFilePath = originalFilePath.replace(new RegExp("\.java"), "new.java");
var lineNum = 0;
try {
// Open file and search for "Copyright" or "Copyright"
var InTextStream = FSO.OpenTextFile (originalFilePath, ForReading, true, TriStateFalse );
lineNum=6;
// Open output file
var OutTextStream = FSO.CreateTextFile(modifiedFilePath,true,false);
lineNum = 9;
// Read input file and insert copyright information into files at first line.
OutTextStream.WriteLine(copyright1);
OutTextStream.WriteLine(copyright2 + fe.name);
OutTextStream.WriteLine(copyright2);
OutTextStream.WriteLine(copyright3);
OutTextStream.WriteLine(copyright2);
OutTextStream.WriteLine(copyright4);
OutTextStream.WriteLine(copyright5);
OutTextStream.WriteLine(copyright6);
OutTextStream.WriteLine(copyright7);
OutTextStream.WriteBlankLines(1);
lineNum = 21;
var reg = new RegExp("Copyright");
var foundCR = false;
//If Copyright is found close both streams and delete outstream.
while(!(InTextStream.AtEndOfStream) && (foundCR==false)){
OriginalLine=InTextStream.ReadLine();
OriginalLine=trim(OriginalLine);
foundCR=reg.test(OriginalLine);
OutTextStream.WriteLine(OriginalLine);
}
lineNum = 32;
InTextStream.Close();
OutTextStream.Close();
if (foundCR) {
//Copyright was found so close file input file, delete output file and move to next file
FSO.DeleteFile(modifiedFilePath, true);
//Write name of file to array of file names not modified.
}else{
//Delete original file since we will save modified file over the top of it.
FSO.CopyFile(modifiedFilePath, originalFilePath);
FSO.DeleteFile(modifiedFilePath, true);
//Write name of file to array of file name modified.
}
} catch(e){
alert("An error occured in: AddJavaCopyright(), the error was: " + e.description + "\n The line number was: " + lineNum + "\n Original path: " + originalFilePath + "\n Original path: " + modifiedFilePath);
}
}
</script>
</HEAD>
<BODY>
<FORM name="form1">
<INPUT type="button" onclick="myRecursion()" value="Iterate through dir"><BR>
</FORM>
</BODY>
</HTML>
|