How to list and load only the first file in folder?

12 ビュー (過去 30 日間)
Dawid Strzelczyk
Dawid Strzelczyk 2020 年 4 月 16 日
コメント済み: Dawid Strzelczyk 2020 年 4 月 23 日
Hello,
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 image or the first n images at a given time?
Dawid
  3 件のコメント
Stephen23
Stephen23 2020 年 4 月 23 日
"I have about 1500 image files in a folder and listing all using dir() last too long and sometimes crashes the AppDesigner."
This is not the fault ot dir, it is the fault of a badly written GUI.
I regularly use dir to return the names (and other data) on many thousands of files at once, it never causes a problem.
"Is there a way to list only the first image or the first n images at a given time?"
Basic MATLAB indexing:
S = dir(..);
S(1).name
Dawid Strzelczyk
Dawid Strzelczyk 2020 年 4 月 23 日
The files are on a server and for someone with bad internet connection the loading last about 1-2 minutes.

サインインしてコメントする。

回答 (1 件)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020 年 4 月 23 日
Hi,
By using the 'dir' function, you would know the number of files present in the folder. You can then access the required number of files using a loop and by accessing the 'name' property of the file. The following might serve you as an example for displaying the names of first 'n' files.
dirFiles = dir(folderpath);
for i = 1:n
disp(dirFiles(i).name)
end
Similarly you can use other properties like 'folder' to perform your required operation. For more information on 'dir' method refer to the following link
Hope this helps!
  3 件のコメント
Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020 年 4 月 23 日
As far as I understood the question, he just needs a way to access first few files instead of all the files.
Dawid Strzelczyk
Dawid Strzelczyk 2020 年 4 月 23 日
I am looking for another way but thanks for the answer!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by