Solution to slow execution of "uigetfile" function with an enormous number of files in a folder

Fernando Meo el 18 de Dic. de 2024
Actividad más reciente Respuesta de Adam Danz a las el 19 de Dic. de 2024

If you have a folder with an enormous number of files and want to use the uigetfile function to select specific files, you may have noticed a significant delay in displaying the file list.
Thanks to the assistance from MathWorks support, an interesting behavior was observed.
For example, if a folder such as Z:\Folder1\Folder2\data contains approximately 2 million files, and you attempt to use uigetfile to access files with a specific extension (e.g., *.ext), the following behavior occurs:
Method 1: This takes minutes to show me the list of all files
[FileName, PathName] = uigetfile('Z:\Folder1\Folder2\data\*.ext', 'File selection');
Method 2: This takes less than a second to display all files.
[FileName, PathName] = uigetfile('*.ext', 'File selection','Z:\Folder1\Folder2\data');
Method 3: This method also takes minutes to display the file list. What is intertesting is that this method is the same as Method 2, except that a file seperator "\" is added at the end of the folder string.
[FileName, PathName] = uigetfile('*.ext', 'File selection','Z:\Folder1\Folder2\data\');
I was informed that the Mathworks development team has been informed of this strange behaviour.
I am using 2023a, but think this should be the same for newer versions.
Adam Danz
Adam Danz el 19 de Dic. de 2024
Thanks for sharing this!
goc3
goc3 el 18 de Dic. de 2024
That is indeed odd. Thanks for sharing.
I imagine that this will be fixed in a future release, but this information could still be helpful for those using older releases (and until it is fixed).
Fernando Meo
Fernando Meo el 19 de Dic. de 2024
Yes indeed. Mathworks support wrote me that this issue was sent to Mathworks development team. I hope they fix this.
The user @dbp on another discussion thread suggested a generic solution to make sure there is no filesep at the end of the path string.
[FileName, PathName] = uigetfile('*.ext',Title, strip(FolderString, 'right', filesep),' multiselect','on');