1

I have about 1500 image files in a folder and listing all using dir() last too long and sometimes crashes the AppDesigner. Is there a way to list only the first or the first n images at a given time?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • Don't think that's possible with `dir`. How would you determine the first n images? Is it based on timestamp or filename? – Paolo Apr 16 '20 at 10:52
  • It is based on filename. I would be also happy with only the first image in folder. The filenames are almost identical: `d_Seite_01.jpg` (the number changes). – Dawid Archibald Apr 16 '20 at 11:30
  • Are you sure the call of `dir` causes your problems? Just tried it in a folder which has 5000 files and it flawlessly returns in <0.05s. – Daniel Apr 16 '20 at 14:57
  • It came to my mind that I am in home office with poor internet connection and the data is on a university server... Thanks! – Dawid Archibald Apr 16 '20 at 15:22

1 Answers1

1

No, this is not possible, because dir essentially is a wrapper of a operation system function (such as the Windows dir and the Linux 'ls'). So now you have two (actually three but you're not gonna like at least one of them^^) options

  1. it shouldn't cause much trouble to call 1500 files. Have a look if it is really the dir command, which causes trouble. Use the Rund and Time functionality in the Editor
  2. use dir with a pattern. Eg. lst = dir() returns an array of structs with everything in the current folder -- including . and .., which are usually nothing you need. Use lst = dir('*.m') instead to get all .m files. In your case, it can be lst = dir('d_Seite_*.jpg'). I am not sure if that saves you much time but at least memory
  3. restructure how your data (images) is stored so that there are less files available. You could run a background task that moves only the n latest files into the folder latest_files and moves them out again if there are newer ones...
max
  • 3,915
  • 2
  • 9
  • 25