Reputation: 745
I've been unable to find anything similar to my apparently niche case.
I have many .png files, all of which have a rectangular or square transparency on them. I have created a script which finds the bounds, and writes this info to a text file.
Currently the behaviour is that the script creates a single text file for each image, and writes the info I need to that file.
The code is currently as follows:
//Create logfile FOLDER on the desktop
var LogFolder = new Folder(Folder.desktop + "/LogFiles/");
if(!LogFolder.exists) LogFolder.create();
//NOTE TO SELF: Would be optimal if appended to single log file
//Create new LOGFILE in the folder using image name
var Loginfo = new File(Folder.desktop + "/LogFiles/" + activeDocument.name.replace(/\.[^\.]+$/, '') + ".txt");
Loginfo.open("w", "TEXT");
//Write the info to the file
Loginfo.write(activeDocument.name.replace(/\.[^\.]+$/, '') + ", " + selectionWidth + ", " + selectionHeight + ", " + selectionTopLeftXOffset + ", " + selectionTopLeftYOffset);
//Close the log
Loginfo.close();
.
I've started working at it, but have had no luck making it append to a single file:
//Create logfile FOLDER on the desktop
var LogFolder = new Folder(Folder.desktop + "/LogFiles/");
if(!LogFolder.exists) LogFolder.create();
//Append to LOGFILE
var Loginfo = new File(Folder.desktop + "/LogFiles/" + "coords.txt");
Loginfo.open("w", "TEXT");
//Write the info to the file
Loginfo.write(activeDocument.name.replace(/\.[^\.]+$/, '') + ", " + selectionWidth + ", " + selectionHeight + ", " + selectionTopLeftXOffset + ", " + selectionTopLeftYOffset + "\r");
//Close the log
Loginfo.close();
.
Appending to a single file would make the work that follows the creation of the file significantly easier. Any help would be greatly appreciated.
Upvotes: 5
Views: 3893
Reputation: 6949
You're currently "writing" to the file, not "appending".
You should be able to change
Loginfo.open("w", "TEXT");
to
Loginfo.open("a", "TEXT");
Upvotes: 11