select .txt file using a filter like *.txt

4 Ansichten (letzte 30 Tage)
Marty Dutch
Marty Dutch am 26 Mär. 2014
Bearbeitet: Image Analyst am 26 Mär. 2014
Hey Experts,
I want to select a .txt file from a directory. In this directory there is only one .txt file among a bunch of image files. Each time the name of the textfile is different. So I want something like: fopen *.txt I looked everywhere but I cannot find a solution for this on first sight easy problem.
Many thanks! Marten

Akzeptierte Antwort

Image Analyst
Image Analyst am 26 Mär. 2014
Bearbeitet: Image Analyst am 26 Mär. 2014
filePattern = fullfile(yourFolder, '*.txt');
textFiles = dir(filePattern);
If length(textFiles) == 1 then you know there's just one and you can grab that one. If the length > 1 then you might have to let the user select it with uigetfile() or else somehow figure out which one you want from the filename.
  1 Kommentar
Marty Dutch
Marty Dutch am 26 Mär. 2014
Thanks for your prompt repsonse. This was the trick I needed!
Marten

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

nl2605
nl2605 am 26 Mär. 2014
I am not sure if this is the simplest way. But you can use 'uigetfile'. Here you can use the .*txt filter. And then use the filename to open the text file.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by