Adobe Acrobat Pro JavaScript, using a trusted function, to access file system directory and list files in a folder not working
I want to list the files in a folder in a list box that the user can select from. My trusted function code is:
myListFilesInFolder = app.trustedFunction(function(cFolderPath){
app.beginPriv();
var folder = Folder(cFolderPath);
var files = folder.getFiles();
var fileList = [];
for (var i=0; i < files.length; i++) {
if (files[i] instanceof File) {
fileList.push(files[i].name);
}
}
return fileList;
app.endPriv();
});
The code to be run with a button in the PDF is:
var folderPath = "/c/temp/my_files";
var filesArray = myListFilesInFolder(folderPath);
if(filesArray && filesArray.length > 0) {
app.alert("Files found:\n" + filesArray.join("\n"));
} else {
app.alert("No files found or an error occurred.");
}
I get an error in the trusted function saying Folder not defined. Need help on the button code too to show the files listed in a drop down or list box that my user can select from too. I’m trying to cut and paste from examples I can find online, but haven’t been able to make this work.
WES
