How to compare contents of folders, check for missing files?

조회 수: 6 (최근 30일)
Louise Wilson
Louise Wilson 2019년 10월 2일
답변: Walter Roberson 2019년 10월 2일
I have a folder of files, which contains .sud files and .wav files. The .wav files are decompressed .sud files and should be equal in number, however, I can see from checking the length of each of these that there is one less .wav file. It looks like one hasn't been processed and I'd like to know which one it is. How can I do this? I've put the filenames in two columns of an array and the empty cell looks like [ ].
Here is my code so far:
directory={'Y:\SoundTrap\Tawharanui\Tawharanui_5278'};
for j=1:length(directory)
folder=char(directory(j));
d=dir(fullfile(folder, '*.wav')); %list all .wav files in path folder
wavfiles=length(d);
%wavfiles=6337
e=dir(fullfile(folder, '*.sud')); %list all .sud files
sudfiles=length(e);
%sudfiles=6338
row=1;
%wavs in first column
for i=1:wavfiles %get filename only (remove prefix and suffix)
disp(d(i).name);
SN=strsplit(d(i).name,'.');
wavfilename=SN(2);
outputfiles(row,1)=wavfilename;
row=row+1;
end
row=1
%suds in second column
for z=1:sudfiles
disp(e(z).name);
SN=strsplit(e(z).name,'.');
sudfilename=SN(2);
outputfiles(row,2)=sudfilename;
row=row+1;
end
end
wavfiles=outputfiles(:,1);
sudfiles=outputfiles(:,2);

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 2일
[~, wav_base_names] = fileparts({d.name});
[~, sud_base_names] = fileparts({e.name});
unmatched_files = setdiff(sud_base_names, wav_base_names);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by