Read files from folder with specific name

20 visualizaciones (últimos 30 días)
Kris zenitis
Kris zenitis el 1 de Jul. de 2014
Comentada: Image Analyst el 17 de Ag. de 2022
I am using the following code to read all files from a folder:
Files=dir('*');
for k=1:length(Files)
FileNames=Files(k).name;
end
However I want to read the files which names begin with "word" not just all files in folder. How can I perform such task?

Respuesta aceptada

Image Analyst
Image Analyst el 1 de Jul. de 2014
Files=dir('word*.*');
  7 comentarios
Ihaveaquest
Ihaveaquest el 16 de Ag. de 2022
what if there are multiple files with similar name but you only want the most current created ??
Image Analyst
Image Analyst el 17 de Ag. de 2022
@Ihaveaquest, to find the newest file, do this:
fileList = dir('t*.m')
fileDates = [fileList.datenum]
% Find newest file
[maxDate, index] = max(fileDates)
fprintf('The newest file is:\nName: %s\nDate: %s\n', ...
fileList(index).name, fileList(index).date)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by