필터 지우기
필터 지우기

How to utilize results of dir command.

조회 수: 3 (최근 30일)
Nicki
Nicki 2013년 11월 12일
댓글: Image Analyst 2013년 11월 12일
Hi, I am trying to use some code in a program of mine, that enables me to search for a file. In my treatment of data, I will always get only one result with the command:
dir * full *.xls (I have added some spaces on the sides of full, in order to keep things looking as they do in my command window.)
This command returns a string to me.
How do I save this string, or in any other way use this handle to open this exact file? I cannot store it to a variable using a command like:
Secretfilename=dir * full *.xls
In all this it is central that I do not know the entire name of the file I need. I only know that using this command will give said file as the only result.
Best regards, Nicki.

채택된 답변

Walter Roberson
Walter Roberson 2013년 11월 12일
Use the function form of dir().
I am not sure what
* full *.xls
would be intended to mean. Possibly the equivalent would be
Secretfileinfo = dir('* full *.xls');
then possibly
fopen(Secretfileinfo.name, 'r')
It might be more complex if the "* full" is intended to designate a directory.
  댓글 수: 2
Nicki
Nicki 2013년 11월 12일
The * full * is a part of the filename, that narrows my result down to one, everey time. It is part of a treatment of a larger dataset I've sorted into subfolders beforehand. Your tip was spot on, I just needed a parenthesis, newbie mistakes are also for the semi-experienced I guess.
Thank you, I believe my problem to be solved.
Image Analyst
Image Analyst 2013년 11월 12일

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

추가 답변 (1개)

EiGeN
EiGeN 2013년 11월 12일
편집: EiGeN 2013년 11월 12일
TargetFolder = d:\Test;
FileList = dir(fullfile(TargetFolder,'*full*.xls');
% or make string use sprintf function
N = length(FileList);
for k = 1 : N
filename = fullfile(TargetFolder,FileList(k).name);
num = xlsread(filename)
...
end

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by