Error: too many open files

Hi,

When I’m reading a lot of files at the same time with getEntries, eventually appears this error.

  try {
    const entries = await aFolder.getEntries();
    const allFiles = entries.filter(entry => entry.isFile);
  } catch (error) {
    console.error(error);
  }

Error: too many open files

I need more information, or how to solve it, becuase I didn’t found information about this

Thanks

seems like a limitation set by Adobe
you can use require('fs') > readdir()
it will return strings/paths that you can use stats to check if is file or folder.

if you need an entry you can getEntryFromUrl with required path.

read more about the FS API

1 Like

It sounds nice.

I am trying to import this new “fs”, but I get an error

Module not found: Error: Can’t resolve ‘fs’

I am in Photoshop 24.5, with manifestVersion 5

In case you’re using webpack you have to add fs to your config (as explained here ), like:

externals: {
    ...
    fs: 'commonjs2 fs',
    ...
  },
1 Like

UXP doesn’t impose any hard limit but that error could be rather from the OS which limits the number of file handles that can be opened by a process. What platform are you working on and how many files are you trying to open? On Mac, for instance, you can check the number of files allowed per process by typing in

ulimit -n

and then check how many files are open by Photoshop currently by using

lsof -p <Process ID of Photoshop>|wc -l

or using the Activity Monitor application and using the tab Open Files and Ports for Photoshop.

1 Like

I did it in mac and shows this:
ulimit - n
256
lsof -p 45183|wc -l
922

May be it is cumulative? Because I am not reading a lot at the same time, is like after a time using the panel, appears this message, and I have to restart Photoshop.

Can we close in some way the entry file after read?

I would double check to make sure you’re storing the file entry objects in a non-global scope, so they are eligible for garbage collection and hence can release the corresponding system resource.

in his case he’s accessing all entries in a folder and looping through them, so I guess it wont get garbage collected since it’s all stores in one big array and he is still in the same scope.

I still think it’s better practice to readdir() and loop through simple strings and only create and entry when necessary.

no need for the overhead of localfilesystem for simple name/type check.

1 Like

Finally it seems that require(‘fs’) works better. No bug for now. Thanks