필터 지우기
필터 지우기

Finding files in directory with two different strings in filename

조회 수: 11 (최근 30일)
Shri Chand
Shri Chand 2023년 7월 7일
댓글: Shri Chand 2023년 7월 7일
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