Borrar filtros
Borrar filtros

Finding files in directory with two different strings in filename

11 visualizaciones (últimos 30 días)
I have a directory which is a folder (called 'DBDIR' below) and I want to find all of the files in this directory that contain two separate strings ('case#' and 'PPG') in the filename. With the below code, I can locate all files in the folder 'CNAP PPG Database' that contain the string 'case#' in the filename.
DBDIR = '/Users/me/CNAP PPG Database';
ggg = dir([DBDIR,'/case#*.mat']);
I am trying to do this to find files that have both 'case#' and 'PPG' in the filename, so I want to do something like below (this of course didn't work though).
DBDIR = '/Users/me/CNAP PPG Database';
ggg = dir([DBDIR,'/case#**PPG.mat']);
To clarify, my list of files in the directory looks like:

Respuesta aceptada

Stephen23
Stephen23 el 7 de Jul. de 2023
Editada: Stephen23 el 7 de Jul. de 2023
Use FULLFILE rather than concatenating text together.
Here is a simple approach that solves the problem you pose in your question:
DBDIR = '/Users/me/CNAP PPG Database';
ggg = [...
dir(fullfile(DBDIR,'*case#*PPG*.mat'));...
dir(fullfile(DBDIR,'*PPG*case#*.mat'))]
Here is a simple approach that works with the filenames that you actually have:
DBDIR = '/Users/me/CNAP PPG Database';
ggg = dir(fullfile(DBDIR,'case#*PPG*.mat'))

Más respuestas (1)

Image Analyst
Image Analyst el 7 de Jul. de 2023

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by