Filter löschen
Filter löschen

How to sort the files in a folder by date?

152 Ansichten (letzte 30 Tage)
Salad Box
Salad Box am 31 Jan. 2019
Kommentiert: J Tian am 9 Nov. 2020
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)?

Akzeptierte Antwort

Stephen23
Stephen23 am 31 Jan. 2019
Bearbeitet: Stephen23 am 31 Jan. 2019
S = dir(...);
S = S(~[S.isdir]);
[~,idx] = sort([S.datenum]);
S = S(idx)
  3 Kommentare
Anupam Parlikar
Anupam Parlikar am 12 Sep. 2019
This works. Thank you!
J Tian
J Tian am 9 Nov. 2020
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by