admin管理员组文章数量:1352863
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.
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.
Share Improve this question asked Aug 14, 2013 at 19:41 DouglasDouglas 7453 gold badges11 silver badges26 bronze badges1 Answer
Reset to default 11You're currently "writing" to the file, not "appending".
- // open() method
- fileExample.open("w"); // write
- fileExample.open("e"); // edit
- fileExample.open("a"); // append
You should be able to change
Loginfo.open("w", "TEXT");
to
Loginfo.open("a", "TEXT");
本文标签: javascriptAppend to an existing text file using Photoshop Scripting ( jsx )Stack Overflow
版权声明:本文标题:javascript - Append to an existing text file using Photoshop Scripting ( .jsx ) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743894195a2557483.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论