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

14 views (last 30 days)
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);

Accepted Answer

Walter Roberson
Walter Roberson on 2 Oct 2019
[~, wav_base_names] = fileparts({d.name});
[~, sud_base_names] = fileparts({e.name});
unmatched_files = setdiff(sud_base_names, wav_base_names);

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!