Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to retrieve file extensions from UIPUTFILE

Status
Not open for further replies.

lehmannkai

Electrical
Joined
Sep 25, 2003
Messages
7
Location
DE
Hi,

I use UIPUTFILE to query for a path % file. Also 4 different file extensions are given in the query figure (*.eps, *.bmp, *.tif, *.jpg).

How can I retrieve the file extension selected by the user?

The user selects *.jpg for example. The entered filename is "test" only. How can I know that the user wants a jpg file to be saved if the only outputs are path and filename but not file extension?

Regards,
Kai
 
UIPUTFILE's third output argument is what your looking for.

Try this

Code:
[filename, pathname, filterindex] = uiputfile( ...
{'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)';
 '*.m', 'M-files (*.m)'; ...
 '*.fig','Figures (*.fig)'; ...
 '*.mat','MAT-files (*.mat)'; ...
 '*.mdl','Models (*.mdl)'; ...
 '*.*',  'All Files (*.*)'}, ...
 'Save as');
 
Hi JockeK,

thanks for your advise. Bit the thirs argument 'filetrindex' applies for Matlab Versions from 6.5 only doesn't it? I only have Version 6.2 available. What can I do?

Regards,
Kai
 
This is another solution

Code:
[filename, pathname] = uiputfile( .... );
[file, extension] = strtok(filename, '.');
 
Hi,

but that leads me off the actual problem. I worry about the case that the given filename is entered without extension. However, a filter eg. ".mat" was specified. I could attach the ".mat" in my function but how can I know that the user specified "*.mat" ????

There doesn't seem to be a way out...

Kai
 
Isn't the chosen filter added automatically to the filename? Oh, now I see that it's not added if the user doesn't choose a filter.
I that case you can assume that it's the first extension in the list you should append to the filename.

I believe you could solve the problem by doing something like this...

1. Check the extension with the strtok-function as described above.
2a. If there is no extension you just add the first extension in the list you specified in your call to uiputfile.
2b. If an extension exists you don't have to do anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top