Login  Register

appending text to a txt file

Posted by John Alexander-7 on Jul 26, 2008; 11:48pm
URL: http://imagej.273.s1.nabble.com/appending-text-to-a-txt-file-tp3695513.html

Hello group,

I am batch processing a ton of files - and I am writing the name of each
file processed into a log file.  I am also recording which files threw
an exception in an error log file.

My approach was to just open the log file, append the information, then
close it.

I believe the two snippets of code below were working just fine a few
months ago - but now they seem to overwrite the file rather than append
to it.

Can someone confirm that this is happening - or is there a mistake in
how I am trying to append to a text file.

I want the file to be appended before and after each image processed so
as to help me identify corrupted files which crash the macro.

Thanks,

John



//begin snippet one
if ((ImageLogFile==true)&&(MasterSave==true)) {
        imagefilelog=File.open(dir+File.separator+"ImageLog.txt");
        print(imagefilelog,SLDdir+"\t"+SLDname+"\n");
        File.close(imagefilelog);
}
//end


and


//begin snippet two
if (isOpen("Exception")) {
        selectWindow("Exception");
        run("Close");
        logfile=File.open(dir+File.separator+"Error_Log.txt"+"\n");
        print(logfile,"SLD: "+SLD+":   "+SLDdir+SLDname+" threw an exception");
        File.close(logfile);
}
//end