Effacer les filtres
Effacer les filtres

Finding files in directory with two different strings in filename

11 vues (au cours des 30 derniers jours)
Shri Chand
Shri Chand le 7 Juil 2023
Commenté : Shri Chand le 7 Juil 2023
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:

Réponse acceptée

Stephen23
Stephen23 le 7 Juil 2023
Modifié(e) : Stephen23 le 7 Juil 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'))

Plus de réponses (1)

Image Analyst
Image Analyst le 7 Juil 2023

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by