Select Git revision
ActivityLogDtoTests.cs
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
fileCompare.m 1.55 KiB
function [status, id] = fileCompare(filename,fileList)
%fileCompare checks if file1 is (binary) identical to a file in filelist
% it returns a sttus and the id of the identical file
% the function uses the windows system function fc or the unix function
% diff
if isempty(fileList)
% no comparison necessary
status =false;
id = 0;
return
end
[~,~,ext1] = fileparts(filename);
id = zeros(height(fileList),1);
for i=1:height(fileList)
[~,~,ext2] = fileparts(fileList{i,'name'});
if ~isequal(ext1,ext2)
%warning('File extension are not identical');
status = false;
continue
end
filepath = fullfile(fileList{i,'folder'},fileList{i,'name'});
%% old
%crucial performance due to matlab bug
%(see
%https://de.mathworks.com/matlabcentral/answers/338553-performance-of-system-dos-function)
if ispc
filename = ['"',filename,'"'];% Bugfix for spaces in path
[status,~] = system(['fc ' filename ' ' char(filepath)]);
% 0 -> identical, 1 -> not identical
status = ~status; % false (not identical), true(identical)
elseif isunix %untested!
[status,~] = system(['diff ' filename ' ' filepath]);
else
warning('Platform not supported')
end
%%
if status == 1
id(i) = 1;
id =logical(id); %bugfix
return;
else
% Status can also be any other number e.g. 2
id(i) = 0;
end
id =logical(id); %bugfix
end
end