I'd just use the fileparts() function.
[sPath, sFilename, sExt] = fileparts( sFile );
sFileBase = [ sPath, sFilename];
As a hint for your method, you can do open fileparts and look at the source code.
Let's try:
[sFiles, sPath] = uigetfile({'*.xls;*.xlsx','Select Excel files'; ...
'*.*', 'Select any file'}, ...
'MultiSelect', 'on');
and select 'Boolk1.xls', 'Book1.xlsx' and 'Book1.txt'. sFiles is a cell array of strings, so we can do this:
for i = 1:length(sFiles)
[~, sFilename, sExt] = fileparts( sFiles{i} );
if( strcmpi( sExt, '.xls' ) )
fprintf( '%s%s is a .xls file.\n', sFilename, sExt );
elseif( strcmpi( sExt, '.xlsx' ) )
fprintf( '%s%s is a .xlsx file.\n', sFilename, sExt );
else
fprintf( '%s%s is neither a .xls nor a .xlsx file.\n', sFilename, sExt );
end
end
the result is:
Book1.txt is neither a .xls nor a .xlsx file.
Book1.xls is a .xls file.
Book1.xlsx is a .xlsx file.
(Matlab is easy!)
dir? If so any reason you can't specify*.xls*? - Danfilepartswhich will help here instead of regex - Dan