Skip to main content
Participating Frequently
February 19, 2026
Question

Adobe Acrobat Pro JavaScript, using a trusted function, to access file system directory and list files in a folder not working

  • February 19, 2026
  • 2 replies
  • 43 views

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
 



 

    2 replies

    wes@ESAAuthor
    Participating Frequently
    February 19, 2026

    Thank you for the reply.  AI responses on the internet say:

     

    var myFolderFunc = app.trustedFunction(function(path) {

    app.beginPriv();

    var myFolder = Folder(path);

    app.endPriv();

    return myFolder;

     

    should work; but when I try it I get:   ReferenceError: Folder is not defined.

    Do you have any other ways to be able to get the files names in a specified directory to show up in a list that my user can pick?   Thank you for your time and for answering.  WES

     

     

    Bernd Alheit
    Community Expert
    Community Expert
    February 19, 2026

    This is not possible with a script in Acrobat.

    wes@ESAAuthor
    Participating Frequently
    February 19, 2026

    Thank you for the reply.  AI responses on the internet say:

     

    var myFolderFunc = app.trustedFunction(function(path) {

    app.beginPriv();

    var myFolder = Folder(path);

    app.endPriv();

    return myFolder;

     

    should work; but when I try it I get:   ReferenceError: Folder is not defined.

    Do you have any other ways to be able to get the files names in a specified directory to show up in a list that my user can pick?   Thank you for your time and for answering.  WES