How to sort the files in a folder by date?

159 views (last 30 days)
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)?

Accepted Answer

Stephen23
Stephen23 on 31 Jan 2019
Edited: Stephen23 on 31 Jan 2019
S = dir(...);
S = S(~[S.isdir]);
[~,idx] = sort([S.datenum]);
S = S(idx)

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!