0001 function [file, ext, dirPath] = fileext(inputFileName)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 [file, ext, dirPath] = deal([]);
0035
0036 if strcmp(class(inputFileName), 'cell')
0037 fileName = inputFileName{1};
0038 if ~strcmp(class(fileName), 'char')
0039 fileName
0040 error('fileext: fileName must be a string')
0041 end
0042 elseif strcmp(class(inputFileName), 'char')
0043 fileName = inputFileName;
0044 else
0045 inputFileName
0046 error('fileext: inputFileName must be either cell or char class')
0047 end
0048
0049 I = find(fileName == '.');
0050
0051
0052
0053 if isempty(I)
0054 inputFileName
0055 error(['fileext: inputFileName starts with a . and does not have a '...
0056 'valid directory path'])
0057 end
0058
0059 if length(I) > 1 & I(1) == 1
0060
0061 D = find(fileName == '/' | fileName == '\');
0062
0063 if isempty(D)
0064 inputFileName
0065 error(['fileext: inputFileName starts with a . and does not have '...
0066 'a valid directory path'])
0067 end
0068 file = fileName(D(end)+1:I(end)-1);
0069 ext = fileName(I(end)+1:end);
0070 dirPath = fileName(1:D(end));
0071 elseif length(I) == 1 & I(1) ~=1 & I(1) ~= length(fileName)
0072
0073 file = fileName(1:I(end)-1);
0074 ext = fileName(I(end)+1:end);
0075 else
0076 inputFileName
0077 error('fileext: inputFileName is improperly formatted')
0078 end
0079
0080
0081 file = file(:)';
0082 ext = ext(:)';
0083 dirPath = dirPath(:)';
0084
0085 return