How to retrieve file extensions from UIPUTFILE
How to retrieve file extensions from UIPUTFILE
(OP)
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
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





RE: How to retrieve file extensions from UIPUTFILE
Try this
[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');
RE: How to retrieve file extensions from UIPUTFILE
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
RE: How to retrieve file extensions from UIPUTFILE
[filename, pathname] = uiputfile( .... );
[file, extension] = strtok(filename, '.');
RE: How to retrieve file extensions from UIPUTFILE
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
RE: How to retrieve file extensions from UIPUTFILE
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.