parseing a filename [ex. .xls vs .dat] in order to pick correct menu to follow

1 view (last 30 days)
hi, i'm trying to have my program ask for an input of a filename. this file can either be an excel file or a .dat file. I want the program to be able to differentiate between wether the file is an .xls or .dat so it can perform the correct operation. my assumption is that it would need to read the filename as a string, set up the delimiter at the '.' before the extension, and then parse the filename at that point and analyze wether it is an excel or .dat file based on what comes after the delimiter. however, I don't know how to go through with this in the coding. If anyone has insight as to how I should go about this, please let me know, I'm kind of stuck. Thank you.

Accepted Answer

Fangjun Jiang
Fangjun Jiang on 19 Dec 2011
filename='xyz.dat';
[pathstr,name,ext]=fileparts(filename);
if strcmpi(ext,'.dat')
% do something
elseif strcmpi(ext,'.xls')
% do something
end

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!