×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to retrieve file extensions from UIPUTFILE

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

RE: How to retrieve file extensions from UIPUTFILE

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

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

(OP)
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

RE: How to retrieve file extensions from UIPUTFILE

This is another solution

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

RE: How to retrieve file extensions from UIPUTFILE

(OP)
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

RE: How to retrieve file extensions from UIPUTFILE

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources