MATLAB: There are specified folders in an specified directory that contents of some of them are equals to contents of others

deletefilefolderMATLABsimilar

there are specified folders in an specified directory that contents of some of them are equals to contents of others. the only difference between these folders is the name of them (other properties like:size,numbers of inside files, inside files names,.. are same) its needed to keep only one of these folder and delete other similar folders.
for example in specified directory there are these folders:a,b,c,d,f,g,h,j,….
a,f,r are equal and also b,t,l,o are equal too. now its needed to keep 'a' and delete 'f,r' and also to keep 'b' and delete t,l,o
i use this code for gathering the names of files that are inside each folder: http://www.mathworks.com/matlabcentral/fileexchange/30835-getcontents
and use these command but it doesn't work correctly
EDITED
Directory='D:\Cl\Clas\'; % this is the same specified directory that i told in the question
FolderNames=get_contents(Directory);%this gives names of folders that i want to comparing them (there are 280 folders)
NumbersOfFolders=size(get_contents(Directory),1);
cd(Directory);
for i=1:NumbersOfFolders
A_dir=dir(FolderNames{i,1});
A_dir=rmfield(A_dir,'date');
for j=1:NumbersOfFolders
B_dir=dir(FolderNames{j,1});
B_dir=rmfield(B_dir,'date');
a=isequal(A_dir, B_dir);
if a==1
rmdir(FolderNames{j,1},'s')
end
end
end
Now there are 2 problems: 1- one of the equals folders must be keep but not has been kept
2- after deleting some folders errors :
??? Error using ==> rmdir
D:\Cl\Clas\foldername is not a directory.
Error in ==> folderdeletingm at 40
rmdir(FolderNames{j,1},'s')
because this folder(FolderNames{i,1}) has been deleted in loop 2 when FolderNames{j,1} = FolderNames{i,1}. also itself is deleted in second loop too and this cause this error

Best Answer

Directory = 'D:\Cl\Clas\';
FolderNames = get_contents(Directory);
NumbersOfFolders = numel(FolderNames); % Faster
cd(Directory);
for i = 1:NumbersOfFolders
% Exclude '.' and '..':

A_dir = dir(FolderNames{i});
A_name = {A_dir.name};
index = or(strcmp(A_name, '.'), strcmp(A_name, '..'));
A_dir = A_dir(~index);
A_dir = rmfield(A_dir,'date');
for j = (i+1):NumbersOfFolders % (i+1) instead of 1 !!!
if exist(FolderNames{j}, 'dir') == 0 % [EDITED]


continue; % [EDITED]
end % [EDITED]
% Exclude '.' and '..':
B_dir = dir(FolderNames{j});
B_name = {B_dir.name};
index = or(strcmp(B_name, '.'), strcmp(B_name, '..'));
B_dir = B_dir(~index);
B_dir = rmfield(B_dir, 'date');
if isequal(A_dir, B_dir)
rmdir(FolderNames{j}, 's')
end
end
end