How to sort the files in a folder by date?

조회 수: 47 (최근 30일)
Salad Box
Salad Box 2019년 1월 31일
댓글: J Tian 2020년 11월 9일
Hi,
For example, I have 3 image files in a folder, looks like below (Fig 1).
10.png
I then tried to get the information of the image files by:
startpath=pwd;
>> list=dir(startpath);
I get (Fig 2):
11.png
I wonder how can I sort the files in the list (excluding the top two '.' and '..') by date (from early to late)?

채택된 답변

Stephen23
Stephen23 2019년 1월 31일
편집: Stephen23 2019년 1월 31일
S = dir(...);
S = S(~[S.isdir]);
[~,idx] = sort([S.datenum]);
S = S(idx)
  댓글 수: 3
Anupam Parlikar
Anupam Parlikar 2019년 9월 12일
This works. Thank you!
J Tian
J Tian 2020년 11월 9일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by