Finding files in directory with two different strings in filename

11 次查看(过去 30 天)
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:

采纳的回答

Stephen23
Stephen23 2023-7-7
编辑:Stephen23 2023-7-7
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'))

更多回答(1 个)

Image Analyst
Image Analyst 2023-7-7

类别

Help CenterFile Exchange 中查找有关 Database Toolbox 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by