FileCompare

PURPOSE ^

fileCompare checks if file1 is (binary) identical to a file in filelist

SYNOPSIS ^

function [status, id] = fileCompare(filename,fileList)

DESCRIPTION ^

fileCompare checks if file1 is (binary) identical to a file in filelist
 it returns a sttus and the id of the identical file
 the functions uses the windows system function fc or the unix function
 diff

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [status, id] = fileCompare(filename,fileList)
0002 %fileCompare checks if file1 is (binary) identical to a file in filelist
0003 % it returns a sttus and the id of the identical file
0004 % the functions uses the windows system function fc or the unix function
0005 % diff
0006 
0007 if isempty(fileList)
0008    % no comparison necessary
0009     status =false;
0010     id = 0;
0011     return
0012 end
0013 
0014 [~,~,ext1] = fileparts(filename); 
0015 id = zeros(height(fileList),1);
0016 
0017 for i=1:height(fileList)
0018     [~,~,ext2] = fileparts(fileList.name(i));
0019 
0020     if ~isequal(ext1,ext2)
0021         %warning('File extension are not identical');
0022         status = false;
0023         continue
0024     end
0025 
0026     filepath = fullfile(fileList.folder{i},fileList.name{i});
0027     if ispc
0028         [status,~] = system(['fc ' filename ' ' filepath]);
0029         % 0 -> identical, 1 -> not identical
0030          status = ~status; % false (not identical), true(identical)
0031                    
0032     elseif isunix %untested!
0033         [status,~] = system(['diff ' filename ' ' filepath]);
0034     else
0035         warning('Platform not supported')
0036     end
0037     
0038     if status == 1        
0039         id(i) = 1;
0040     else 
0041         % Status can also be any other number e.g. 2
0042         id(i) = 0;
0043     end
0044     
0045     id =logical(id); %bugfix
0046 end
0047 
0048 end
0049

Generated on Tue 03-Aug-2021 18:32:18 by m2html © 2005