pick files within dir

1 ビュー (過去 30 日間)
Ihaveaquest
Ihaveaquest 2022 年 9 月 14 日
コメント済み: Ihaveaquest 2022 年 9 月 15 日
I have a list create by dir
i want to pick specific files in the dir the name differentiators are genreal name with "post" on the title and without
I want to pick "post" files to create new table with the
files = dir(test{2});
match = readnames(files.name,'Post'); %I know this is wrong but im not sure hwat else to try
comp.files = match;
x = size(comp.files);
help please
  1 件のコメント
Ihaveaquest
Ihaveaquest 2022 年 9 月 15 日
it all looks great thak you i figured it out
files = dir(fullfile('*Comp*Post*'));
this si what i was looking for .. thank sorry for the misunderstanding

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 14 日
dinfo = dir('*post*');
comp.files = fullfile({dinfo.folder}, {dinfo.name});
numfiles = length(comp.files);
Now comp.files will be a cell array of character vectors, each of which is a fully-qualified file name that has "post" as part of the name.
For other files without "post" the code is slightly longer
npdinfo = dir('*');
ndpinfo([ndpinfo.isdir]) = []; %remove . and .. and any folder names
npdinfo(contains({npdinfo.name}, 'post')) = []; %remove names containing 'post'
comp.npfiles = fullfile({npdinfo.folder}, {npdinfo.name});
numnpfiles = length(comp.npfiles);
... If you are wanting both lists, then it is easier to just do one pass, like
dinfo = dir('*');
dinfo([dinfo.isdir]) = []; %remove . and .. and any folder names
mask = contains({dinfo.name}, 'post');
comp.files = fullfile({dinfo(mask).folder}, {dinfo(mask).name});
numfiles = length(comp.files);
comp.npfiles = fullfile({dinfo(~mask).folder}, {dinfo(~mask).name});
  7 件のコメント
Walter Roberson
Walter Roberson 2022 年 9 月 14 日
dinfo = dir(fullfile(test{2}, '*'));
dinfo([dinfo.isdir]) = []; %remove . and .. and any folder names
mask = contains({dinfo.name}, 'post') & contains({dinfo.name}, 'comp');
comp.files = fullfile({dinfo(mask).folder}, {dinfo(mask).name});
numfiles = length(comp.files);
comp.npfiles = fullfile({dinfo(~mask).folder}, {dinfo(~mask).name});

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Find more on File Operations in Help Center and File Exchange

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by