Thread Subject: directory reader

Subject: directory reader

From: Mamata Kukreja

Date: 12 Feb, 2008 13:23:03

Message: 1 of 7


I want to read a specific directory and display the files in
a list box ..
whats wrong with this code ..

    directory = 'C:\......\WORK'; % some directory path
      
    cd(directory);
    
    d=directory;
   
    filenames={};in=1;
    for index=1:length(d);
       if d(index).isdir~=1;
          filenames{in}=d(index).name;
          in=in+1;
       end;
    end;
    
    set(handles.listbox1,'string',filenames);

   

Subject: directory reader

From: Mamata Kukreja

Date: 12 Feb, 2008 14:17:02

Message: 2 of 7

"Mamata Kukreja" <mamata_kukreja@yahoo.com> wrote in message
<fos6jn$l3c$1@fred.mathworks.com>...
>
> I want to read a specific directory and display the files in
> a list box ..
> whats wrong with this code ..
>
> directory = 'C:\......\WORK'; % some directory path
>
> cd(directory);
>
> d=directory;
>
> filenames={};in=1;
> for index=1:length(d);
> if d(index).isdir~=1;
> filenames{in}=d(index).name;
> in=in+1;
> end;
> end;
>
> set(handles.listbox1,'string',filenames);
>
>
?????????

Subject: directory reader

From: alessandro mura

Date: 11 Feb, 2008 15:10:06

Message: 3 of 7



On Tue, 12 Feb 2008 13:23:03 +0000, Mamata Kukreja wrote:



>
> I want to read a specific directory and display the files in
> a list box ..
> whats wrong with this code ..

"directory" is a variable in your code. Use dir.
help dir


--
Alessandro Mura
INAF - Istituto Nazionale di Astrofisica
Roma, Italy
http://pptt4.ifsi-roma.inaf.it/~mura/index.html
http://www.alessandromura.it

Subject: directory reader

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 12 Feb, 2008 15:21:10

Message: 4 of 7

In article <fos6jn$l3c$1@fred.mathworks.com>,
Mamata Kukreja <mamata_kukreja@yahoo.com> wrote:

>I want to read a specific directory and display the files in
>a list box ..
>whats wrong with this code ..
>
> directory = 'C:\......\WORK'; % some directory path
>
> cd(directory);
>
> d=directory;

At this point you want d = dir;

> filenames={};in=1;
> for index=1:length(d);
> if d(index).isdir~=1;
> filenames{in}=d(index).name;
> in=in+1;
> end;
> end;

> set(handles.listbox1,'string',filenames);
--
  "The art of storytelling is reaching its end because the epic
  side of truth, wisdom, is dying out." -- Walter Benjamin

Subject: directory reader

From: Angela Puente

Date: 4 Aug, 2008 20:28:02

Message: 5 of 7

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fosdh6$5eb$1@canopus.cc.umanitoba.ca>...
> In article <fos6jn$l3c$1@fred.mathworks.com>,
> Mamata Kukreja <mamata_kukreja@yahoo.com> wrote:
>
> >I want to read a specific directory and display the files in
> >a list box ..
> >whats wrong with this code ..
> >
> > directory = 'C:\......\WORK'; % some directory path
> >
> > cd(directory);
> >
> > d=directory;
>
> At this point you want d = dir;
>
> > filenames={};in=1;
> > for index=1:length(d);
> > if d(index).isdir~=1;
> > filenames{in}=d(index).name;
> > in=in+1;
> > end;
> > end;
>
> > set(handles.listbox1,'string',filenames);
> --
> "The art of storytelling is reaching its end because the
epic
> side of truth, wisdom, is dying out." -- Walter
Benjamin

Along the same lines, is there a way you can add an
additional option to the list at the bottom, like 'Create
new' or something like that? Or can you only list the
directory files?

Subject: directory reader

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 4 Aug, 2008 21:18:32

Message: 6 of 7

In article <g77ooi$qbs$1@fred.mathworks.com>,
Angela Puente <apuente11@verizon.net> wrote:
>roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
>message <fosdh6$5eb$1@canopus.cc.umanitoba.ca>...
>> In article <fos6jn$l3c$1@fred.mathworks.com>,
>> Mamata Kukreja <mamata_kukreja@yahoo.com> wrote:

>> > directory = 'C:\......\WORK'; % some directory path
>> > cd(directory);
>> > d=dir;
>> > filenames={};in=1;
>> > for index=1:length(d);
>> > if d(index).isdir~=1;
>> > filenames{in}=d(index).name;
>> > in=in+1;
>> > end;
>> > end;
>> > set(handles.listbox1,'string',filenames);

>Along the same lines, is there a way you can add an
>additional option to the list at the bottom, like 'Create
>new' or something like that? Or can you only list the
>directory files?

Add a line before the set() call:

filenames{end+1} = 'Create New';

I think you will find, though, that the code is easier to
write and maintain if you make the 'Create New' the *first*
entry in the list rather than the *last* entry in the list.
--
   "Beware of bugs in the above code; I have only proved it correct,
   not tried it." -- Donald Knuth

Subject: directory reader

From: Angela Puente

Date: 4 Aug, 2008 22:15:10

Message: 7 of 7

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <g77rn8$597$1@canopus.cc.umanitoba.ca>...
> In article <g77ooi$qbs$1@fred.mathworks.com>,
> Angela Puente <apuente11@verizon.net> wrote:
> >roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
> >message <fosdh6$5eb$1@canopus.cc.umanitoba.ca>...
> >> In article <fos6jn$l3c$1@fred.mathworks.com>,
> >> Mamata Kukreja <mamata_kukreja@yahoo.com> wrote:
>
> >> > directory = 'C:\......\WORK'; % some directory path
> >> > cd(directory);
> >> > d=dir;
> >> > filenames={};in=1;
> >> > for index=1:length(d);
> >> > if d(index).isdir~=1;
> >> > filenames{in}=d(index).name;
> >> > in=in+1;
> >> > end;
> >> > end;
> >> > set(handles.listbox1,'string',filenames);
>
> >Along the same lines, is there a way you can add an
> >additional option to the list at the bottom, like 'Create
> >new' or something like that? Or can you only list the
> >directory files?
>
> Add a line before the set() call:
>
> filenames{end+1} = 'Create New';
>
> I think you will find, though, that the code is easier to
> write and maintain if you make the 'Create New' the *first*
> entry in the list rather than the *last* entry in the list.
> --
> "Beware of bugs in the above code; I have only proved
it correct,
> not tried it." --
Donald Knuth


Thank you very much! That did the trick.

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