Copy link to clipboard
Copied
#target photoshop;
main();
function main(){
var selectedFolder = Folder.selectDialog("Please select folder");
if(selectedFolder == null) return;
var fileList= selectedFolder.getFiles();
if(fileList.length>0){
var out = new File(Folder.desktop + "/out.txt");
out.open("w");
out.encoding="UTF8";
for(var a in fileList){out.writeln(decodeURI(fileList.name));}
out.close();
}
};
have a folder with more than 1000 jsx files with different filenames, I want to create a text file on the desktop that contains all the files in the folder, but I'm getting errors, please correct me, I'm sorry Thank you
In folder
name1.jsx , name2.jsx, name3.jsx....namen.jsx
I want to get to
["name1","name2",......,"namen"]
#target photoshop;
main();
function main(){
var selectedFolder = Folder.selectDialog("Please select folder");
if(selectedFolder == null) return;
var fileList= selectedFolder.getFiles();
if(fileList.length>0){
var names = "";
for (var i = 0; i < fileList.length; i++) {
if (i==0 ) names = '"' + decodeURI(fileList[i].name) + '"';
else names = names + '\n"' + decodeURI(fileList[i].name) + '"';
}
logInfo(names)
}
}
function logInfo(Txt){
try {
var file = new F
...
Copy link to clipboard
Copied
#target photoshop;
main();
function main(){
var selectedFolder = Folder.selectDialog("Please select folder");
if(selectedFolder == null) return;
var fileList= selectedFolder.getFiles();
if(fileList.length>0){
var names = "";
for (var i = 0; i < fileList.length; i++) {
if (i==0 ) names = '"' + decodeURI(fileList[i].name) + '"';
else names = names + '\n"' + decodeURI(fileList[i].name) + '"';
}
logInfo(names)
}
}
function logInfo(Txt){
try {
var file = new File(Folder.desktop + "/out.txt");
file.open("w", "TEXT", "????");
//alert(file.encoding);
file.encoding = "UTF8";
file.seek(0,2);
$.os.search(/windows/i) != -1 ? file.lineFeed = 'windows' : file.lineFeed = 'macintosh';
file.writeln(Txt);
if (file.error) alert(file.error);
file.close();
file.execute();
}
catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }
};
chamge the \n linefeed to , if you want a single line text file
Copy link to clipboard
Copied
Thanks for the code you edited, it works fine
Copy link to clipboard
Copied
I only hack at scripting I do not know javascript. I knew your code had to process the fileList array elements so I hack it a way I knew how to. Kukurykus knows javascript well I'm sure what he posted would fix your original code.
The logging code is code I came across years ago. I think a single write will perform better then writing names one at a time
Copy link to clipboard
Copied
Codes with no iterator which were still part of Jive:
Copy link to clipboard
Copied
Use:
fileList[a].name
or:
fileList.shift().name