How to sort the files in a folder by date?

155 vues (au cours des 30 derniers jours)
Salad Box
Salad Box le 31 Jan 2019
Commenté : J Tian le 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)?

Réponse acceptée

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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by