How to sort the files in a folder by date?

161 visualizaciones (últimos 30 días)
Salad Box
Salad Box el 31 de En. de 2019
Comentada: J Tian el 9 de Nov. de 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)?

Respuesta aceptada

Stephen23
Stephen23 el 31 de En. de 2019
Editada: Stephen23 el 31 de En. de 2019
S = dir(...);
S = S(~[S.isdir]);
[~,idx] = sort([S.datenum]);
S = S(idx)
  3 comentarios
Anupam Parlikar
Anupam Parlikar el 12 de Sept. de 2019
This works. Thank you!
J Tian
J Tian el 9 de Nov. de 2020
Thanks

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by