how to extract the names of all the files with an specific extension content in different directories and omit the name if is repeated?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
German Preciat Gonzalez
am 28 Jun. 2016
Beantwortet: Jos (10584)
am 28 Jun. 2016
If I want all the name of the files with an extension .jpg in different directories so far I use this:
dir1='~/dir1'
dir2='~/dir2'
dir3='~/dir3'
imageDirs={dir1 dir2 dir3};
fnames=dir([dir1 '/*.jpg']);
files={fnames.name}';
for i=2:length(imageDirs)
fnames=dir([imageDirs{i} '/*.jpg']);
newIm={fnames.name}';
diffIm=setdiff(files,newIm);
files=[files(:);diffIm];
diffIm=setdiff(newIm,files);
files=[files(:);diffIm];
end
files=unique(files);
but I don't think that is efficient at all haha. Any suggestions I will really appreciate that
1 Kommentar
José-Luis
am 28 Jun. 2016
Why do you use setdiff? Do you want the unique names across all three directories?
Akzeptierte Antwort
Jos (10584)
am 28 Jun. 2016
imageDirs = {dir1 dir2 dir3} ;
for k = 1:numel(imageDirs)
flames = dir(fullfile(imageDirs{k}, '*.jpg')) ; % fullfile for cross-OS compatibility
newIm{k} = {fnames.name} ;
end
UniqueIm = unique([newIm{:}])
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!