UIGETFILE to filter out files with specific string

I'm looking to do something fairly simple. I want to use UIGETFILE to have the user get a specific file. The user will be searching for an xml file in a specific folder - and that part I know how to do. I would like to have UIGETFILE further filter the options based on the string of the file. For example, the folder may contain:
Type1A.xml
Type1B.xml
Type2A.xml
Type2B.xml
...
Type7C.xml
and I would like the user to only be able to select (or see) anything that contains "Type1". In this case they should be able to see "Type1A.xml" or "Type1B.xml".
Not sure how to get this to happen with UIGETFILE or if maybe there is a better way around it. The FILTERSPEC in the input allows me to specify "*.xml" but I would ideally only like xml files with a specific string contained within the file name.
Thanks!

답변 (2개)

Image Analyst
Image Analyst 2014년 7월 3일

2 개 추천

Try passing in 'Type*.xml' for the file pattern in uigetfile().

댓글 수: 4

Tried that ... no luck
I tried it and it works fine. What does "no luck" mean to you? Here, try this. Save it as test3.m and run it. What do you see?
% Create a bunch of Type*.xml files in the current folder
% by copying this "test3.m" test script.
copyfile('test3.m', 'Type1.xml');
copyfile('test3.m', 'Type2.xml');
copyfile('test3.m', 'Type03.xml');
copyfile('test3.m', 'Type 4.xml');
[baseFileName, folder] = uigetfile('type*.xml')
Miguel, what's the status of this? Did my answer work now?
It works. I would like to do the same, but to filter just the last letters of the filename.
My Problem: I have the following two files in my folder:
KS_FFT_Pos-7_64364.xlsx
KS_FFT_Pos-7_64364_worked.xlsx
Only the "_worked.xlsx" data works for my following process in MatLab. So I would like to get that the user just have the opinion to select the right excel-data (the worked version).
EDIT: I got it!
It has to be
...uigetfile('*_worked.xlsx',...);

댓글을 달려면 로그인하십시오.

Ben11
Ben11 2014년 7월 3일

0 개 추천

This submission from the file exchange might be what you are looking for:

댓글 수: 1

Thanks Ben. I've used this in the past for selecting multiple files out of different directories, but it seems overkill for what I need.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

질문:

2014년 7월 3일

편집:

2018년 6월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by