function theBytesOut = fcat(theInput, theOutput) % fcat -- Concatenate files. % fcat('theInput', 'theOutput') concatenates all files % encompassed by "dir('theInput')" to 'theOutput' file. % The output file is created if it does not already % exist. The number of bytes output is returned. % Copyright (C) 2000 Dr. Charles R. Denham, ZYDECO. % All Rights Reserved. % Disclosure without explicit written consent from the % copyright owner does not constitute publication. % Version of 19-Jul-2000 15:09:05. % Updated 19-Jul-2000 15:29:15. if nargout > 0, theBytesOut = 0; end if nargin < 2, help(mfilename), return, end if ischar(theInput) theInput = dir(theInput); end if isempty(theInput) disp([' ## ' mfilename ' -- No inputs exist.']) return end fout = fopen(theOutput, 'a'); if fout < 0 disp([' ## ' mfilename ' -- No such output file: ' theOutput]) return end bytes_out = 0; for i = 1:length(theInput) w = which(theInput(i).name); fin = fopen(w, 'r'); if fin >= 0 theBytes = fread(fin); fclose(fin); if ~isempty(theBytes) c = fwrite(fout, theBytes); bytes_out = bytes_out + c; end end end fclose(fout); if nargout > 0, theBytesOut = bytes_out; end