From: Dilip Gopalakrishna on
Hello,
I seek help in accessing files with a particular extension using the dir command. However, I intend to use a variable name inside the dir command instead of explicitly mentioning the path name. Here is the reference code:

Dirname = uigetdir('C:\Documents\MATLAB\TempFolder');
directory = dir(Dirname);

Line 2 gives all files in the directory accessed by the variable name 'Dirname'.
However, to selectively extract say only .m files, I cannot use the '*.m' wildcard operator as follows:
directory = dir(Dirname *.m);
This is a line parse error.
Did not find help with regard to this in documentation too.
How do I use the wildcard operator in this case?
From: Oleg Komarov on
"Dilip Gopalakrishna" <jeedilip(a)yahoo.co.in> wrote in message <hm2urv$sv9$1(a)fred.mathworks.com>...
> Hello,
> I seek help in accessing files with a particular extension using the dir command. However, I intend to use a variable name inside the dir command instead of explicitly mentioning the path name. Here is the reference code:
>
> Dirname = uigetdir('C:\Documents\MATLAB\TempFolder');
> directory = dir(Dirname);
>
> Line 2 gives all files in the directory accessed by the variable name 'Dirname'.
> However, to selectively extract say only .m files, I cannot use the '*.m' wildcard operator as follows:
> directory = dir(Dirname *.m);
> This is a line parse error.
> Did not find help with regard to this in documentation too.
> How do I use the wildcard operator in this case?

You forgot the backslash at the end of dirname.

Oleg
From: Doug Schwarz on
In article <hm2urv$sv9$1(a)fred.mathworks.com>,
"Dilip Gopalakrishna" <jeedilip(a)yahoo.co.in> wrote:

> Hello,
> I seek help in accessing files with a particular extension using the dir
> command. However, I intend to use a variable name inside the dir command
> instead of explicitly mentioning the path name. Here is the reference code:
>
> Dirname = uigetdir('C:\Documents\MATLAB\TempFolder');
> directory = dir(Dirname);
>
> Line 2 gives all files in the directory accessed by the variable name
> 'Dirname'.
> However, to selectively extract say only .m files, I cannot use the '*.m'
> wildcard operator as follows:
> directory = dir(Dirname *.m);
> This is a line parse error.
> Did not find help with regard to this in documentation too.
> How do I use the wildcard operator in this case?


Dirname = uigetdir('C:\Documents\MATLAB\TempFolder');
pattern = fullfile(Dirname,'*.m');
directory = dir(pattern);

--
Doug Schwarz
dmschwarz&ieee,org
Make obvious changes to get real email address.