Thread Subject: Structure handling (DIR output)

Subject: Structure handling (DIR output)

From: Dimitri Shvorob

Date: 7 Oct, 2008 08:01:20

Message: 1 of 4

I would like to get a cell array of strings, listing files and subdirectories in a directory. The best I can manage is:

list = dir;
n = length(list);
x = cell(n,1);
[x{:}] = deal(list(1:n).name)

Is there a better way?

Thank you.
 

Subject: Structure handling (DIR output)

From: Stephan

Date: 7 Oct, 2008 10:25:05

Message: 2 of 4

"Dimitri Shvorob" <not.dimitri.shvorob@gmail.com> wrote in message <gcf50g$l16$1@fred.mathworks.com>...
> I would like to get a cell array of strings, listing files and subdirectories in a directory. The best I can manage is:
>
> list = dir;
> n = length(list);
> x = cell(n,1);
> [x{:}] = deal(list(1:n).name)
>
> Is there a better way?
>
> Thank you.
>

************************************************************

Hi Dimitri

You could make it like that:

list = dir;
x = struct2cell(list);
x = x(1,:);

Cheers Stephan

Subject: Structure handling (DIR output)

From: Dimitri Shvorob

Date: 7 Oct, 2008 12:10:05

Message: 3 of 4

Thanks, Stephan!

Subject: Structure handling (DIR output)

From: Doug Schwarz

Date: 7 Oct, 2008 12:33:26

Message: 4 of 4

In article <gcf50g$l16$1@fred.mathworks.com>,
 "Dimitri Shvorob" <not.dimitri.shvorob@gmail.com> wrote:

> I would like to get a cell array of strings, listing files and subdirectories
> in a directory. The best I can manage is:
>
> list = dir;
> n = length(list);
> x = cell(n,1);
> [x{:}] = deal(list(1:n).name)
>
> Is there a better way?
>
> Thank you.
>

list = dir;
x = {list.name};

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

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com